Pandas: Apply pytz.FixedOffset to a Series

﹥>﹥吖頭↗ 提交于 2021-01-28 09:39:33

问题


I have a DataFrame with a timestamp column which looks like this:

0     2020-01-26 05:00:00-08:00
1     2020-01-26 06:00:00-08:00
[...]
Name: timestamp, dtype: datetime64[ns, pytz.FixedOffset(-480)]

(The timestamp is not the DataFrame's index)

I would like to have that pytz.FixedOffset(-480) applied (or rather un-applied) to the column, so that it would look like this:

0     2020-01-26 13:00:00
1     2020-01-26 14:00:00
[...]

How can I achieve this without parsing timestamp manually?


回答1:


Use Series.dt.tz_convert:

df['timestamp'] = df['timestamp'].dt.tz_convert(None)
print (df)
            timestamp
0 2020-01-26 13:00:00
1 2020-01-26 14:00:00


来源:https://stackoverflow.com/questions/59919877/pandas-apply-pytz-fixedoffset-to-a-series

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!