测试数据
a = pd.DataFrame({'time':[20201010,20200920],'test':[1,2]})
print(a)
a.dtypes
time test
0 20201010 1
1 20200920 2
time int64
test int64
dtype: object
直接转换会出现如下情况
pd.to_datetime(a.time)
0 1970-01-01 00:00:00.020201010
1 1970-01-01 00:00:00.020200920
Name: time, dtype: datetime64[ns]
先将整数类型转换为str类型再转换成功
pd.to_datetime(a.time.astype('str'))
0 2020-10-10
1 2020-09-20
Name: time, dtype: datetime64[ns]
网友评论