我有一个像这样的pandas.dataframe(“col”列有两种格式):
col val
'12/1/2013' value1
'1/22/2014 12:00:01 AM' value2
'12/10/2013' value3
'12/31/2013' value4
我想将它们转换为日期时间格式,考虑使用:
test_df['col']= test_df['col'].map(lambda x: datetime.strptime(x, '%m/%d/%Y'))
test_df['col']= test_df['col'].map(lambda x: datetime.strptime(x, '%m/%d/%Y %H:%M %p'))
显然,它们两个都适用于整个数据框。我在考虑使用try和except但没有成功,有什么建议吗?
for item in test_df.col: test_df.col = datetime.strptime(test_df.col, '%m/%d/%Y')
- Christopher Pearsonpandas
数据框吗? - TigerhawkT3pandas
。抱歉没有提到它...我已经更新了我的问题,谢谢。 - datadatadata