The following DataFrames are available:
install_t
0NaT
1 2020-03-28 19:31:22.159174+09:00
2NaT
3 2019-12-31 10:38:38.165566+09:00
4 2020-06-14 15:29:41.511317+09:00
Name: install_t, dtype: datetime64 [ns, pytz.FixedOffset (540)]
I only want the above install_t column to be dated 2019-12-31
, so I wrote the following code, but there were no errors and there was no change in the results.
Why is that?Thank you for your cooperation.
df['install_t'] = pd.to_datetime(df['install_t'])
df['install_t'] = df['install_t'].dt.round("D")
df ['install_t']
Also, I tried to delete the time zone below, but I got an error.
Help me.
df6['install_t'] = df6['install_t'].replace(tzinfo=None)
------------------------------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-e26e2db5d810>in<module>
---->1df6['install_t'] = df6['install_t'].replace(tzinfo=None)
TypeError: replace() got an unexpected keyword argument 'tzinfo'
I think this article is applicable.
How to remove timezone from a Timestamp column in a pandas dataframe
You can use tz_localize
to change the time zone, an active timestamp corresponds to time zone:
You can change the time zone using tz_localize
.Simple timestamps correspond to the time zone None
:
testdata['time'].dt.tz_localize(None)
Unless the column is an index you have to call method dt
to access pandas datetime functions.
Unless the column is an index, you must invoke the method dt
to access the Pandas date and time function.
If you apply it to your question, it will be as follows:
df['install_t'] = df['install_t'].dt.tz_localize(None)
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
542 Unable to install versioned in Google Colab
546 Understanding How to Configure Google API Key
537 Uncaught (inpromise) Error on Electron: An object could not be cloned
710 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.