我正在将表格从CSV读取到数据框bar
,并且它具有以下列,即日期时间表示为字符串
time_cols = ['created_at', 'updated_at', 'gcreated_at', 'gupdated_at', 'deleted_at']
我用
更改为datetimefor x in time_cols:
bar[x] = pd.to_datetime(bar[x])
然后我尝试做一些日期差异功能并遇到麻烦,所以我检查了每个列的dtype并找到了
for col in time_cols:
print col + " " + str(bar[col].dtype) + "\n"
created_at datetime64[ns]
updated_at datetime64[ns]
gcreated_at object
gupdated_at object
deleted_at datetime64[ns]
关于s / o的另一个问题我也试过了
bar.convert_objects(convert_dates='coerce',convert_numeric=True)
但仍有不匹配的数据类型
如何将这些object
dtypes强制转换为datetime64[ns]
类型?
created_at updated_at gcreated_at gupdated_at
2014-03-26 12:13:34 2014-03-30 01:11:09 2015-07-09 18:40:04.0 2015-07-09 18:40:04.0
2014-03-31 21:40:24 2014-04-02 07:58:11 2014-04-02 07:59:36.0 2014-04-02 07:59:36.0
2014-05-23 23:32:59 2014-05-25 05:52:56 2014-08-21 17:05:01.0 2014-08-21 17:05:01.0