因此,我尝试使用 to_datetime
选项将对象转换为 pandas 日期时间。但是它不起作用。
我的代码:
ship_date = pd.to_datetime(d['shipmentDate'])
print(ship_date.head())
输出:
0 2019-11-08 18:57:31+01:00
1 2019-11-08 16:30:02+01:00
2 2019-11-08 15:28:32+01:00
3 2019-11-08 11:56:32+01:00
4 2019-11-08 11:56:02+01:00
Name: shipmentDate, dtype: object
即使尝试使用如下格式:
ship_date = pd.to_datetime(d['shipmentDate'], format='%Y-%m-%d %H:%M:%S%z')
我仍然得到一个对象而不是日期时间。我做错了什么?
最佳答案
您的日期时间有不同的时区。您可以将 utc=True
传递给 to_datetime
。
关于python - 使用 Pandas to_datetime 将对象转换为日期时间不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58779463/