将字符串转换为pandas中的datetime时遇到问题

时间:2015-07-27 22:15:45

标签: python datetime pandas

In  [67]:

offline['CREATEDDATE'].head()  
Out[67]:  
0    01/05/06  
1    11/22/03   
2    10/31/07  
3    02/05/10  
4    05/16/05  
Name: CREATEDDATE, dtype: object  
In [68]:

offline['CREATEDDATE'] = pd.to_datetime(offline['CREATEDDATE'])  
In [70]:

offline['CREATEDDATE'].head()  
Out[70]:  
0    01/05/06  
1    11/22/03  
2    10/31/07  
3    02/05/10  
4    05/16/05  
Name: CREATEDDATE, dtype: object

1 个答案:

答案 0 :(得分:0)

我测试了你的代码,它工作正常。我建议你检查一下Pandas的版本并在需要时进行升级。

#Check versions. I used 'pandas: 0.16.1', 'numpy: 1.9.2'
pd.show_versions()
df=pd.DataFrame(['01/05/06','11/22/03'], columns=['dates'])
#the format option can be omitted, but I include this for clarity
df['dates']=pd.to_datetime(df['dates'],format='%m/%d/%y')
df['dates']
#out: Name: dates, dtype: datetime64[ns]