【发布时间】:2017-10-15 12:24:33
【问题描述】:
我尝试了很多方法来解决这个问题,但都没有奏效。
我想将pandas 系列转换为datetime。
我想我可能错过了一些小而重要的部分。
print test["order_date"][3]
print type(test["order_date"][3])
test["order_date"] = pd.to_datetime(test["order_date"], format="%Y-%m-%d %H:%M:%S")
##have also tried
##test["order_date"] = pd.to_datetime(test["order_date"], infer_datetime_format=True)
##test["order_date"] = test["order_date"].apply(pd.to_datetime)
##all turn out to be the same result
print test["order_date"][3]
print type(test["order_date"][3])
结果如下:
20150731000001
<type 'numpy.int64'>
1970-01-01 05:35:50.731000001
<class 'pandas.tslib.Timestamp'>
我不明白为什么result 变成1970-01-01
如果需要任何进一步的信息,请告诉我。
谢谢!
【问题讨论】:
-
格式错误,因此数字 20150731000001 自 1970 年以来被解释为 ms - 这与您的结果相对应。