我有一个如下数据框:
A
2014-06-02 09:00:00-04:00 ...
2014-06-02 10:00:00-04:00 ...
2014-06-02 11:00:00-04:00 ...
2014-06-02 12:00:00-04:00 ...
我需要将索引作为日期时间以进行一些操作,所以我正在尝试:
df.index = pd.to_datetime(df.index)
但是我遇到了以下错误
ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True
请注意,索引已本地化(-04:00)
熊猫0.24.2
答案 0 :(得分:2)
您可以遵循错误提示:
df.index = pd.to_datetime(df.index, utc=True)
您还可以将时间转换为带有-04:00
的{{1}}时区