1 回答
TA贡献1853条经验 获得超6个赞
从示例中的格式来看,您需要to_datetime
先使用 kwargsdayfirst=True
和utc=True
(以正确描述输入)进行转换。然后你就可以tz_convert
到相应的时区了。前任:
df['dateuno'] = pd.to_datetime(df['dateuno'], dayfirst=True, utc=True)
df['dateduo'] = pd.to_datetime(df['dateduo'], dayfirst=True, utc=True)
df['dateuno'] = df['dateuno'].dt.tz_convert('US/Eastern')
df['dateduo'] = df['dateduo'].dt.tz_convert('US/Eastern')
# df
# blah dateuno dateduo
# 0 a 2020-06-29 09:27:00-04:00 2020-06-29 13:44:00-04:00
# 1 b 2020-05-19 07:15:00-04:00 2020-05-19 15:25:00-04:00
# 2 c 2020-06-08 07:50:00-04:00 2020-06-08 15:51:00-04:00
# 3 d 2020-06-09 07:37:00-04:00 2020-06-09 15:38:00-04:00
# 4 e 2020-07-20 07:44:00-04:00 2020-07-20 15:47:00-04:00
# 5 f 2020-07-21 07:02:00-04:00 2020-07-21 15:08:00-04:00
# 6 g 2020-07-23 07:01:00-04:00 2020-07-23 15:05:00-04:00
添加回答
举报