import pandas as pd
import datetime as dt
df= pd.DataFrame({'date':["Wed Aug 21 18:51:19 2019"]})
# convert to datetime
df['new_datetime'] =pd.to_datetime(df['date'], format = '%a %b %d %H:%M:%S %Y')
# keep date part only
df['new_date'] =df['new_datetime'].dt.date
您需要找到正确的格式来描述字符串日期
这里是
'%a %b %d %H:%M:%S %Y'
,因为您以%a
:缩写的星期几开始,然后是一个空格'%b'
:缩写的月份日等可以在here中找到可用格式的完整列表
相关问题 更多 >
编程相关推荐