使用熊猫将对象转换为日期时间to_datetime不起作用

时间:2019-11-09 12:48:53

标签: python pandas dataframe

因此,我尝试使用to_datetime选项将对象转换为pandas datetime。但是它不起作用。

我的代码:

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')

我仍然得到一个对象,而不是日期时间。我在做什么错了?

1 个答案:

答案 0 :(得分:1)

您的日期时间具有不同的时区。您可以将utc=True传递到to_datetime