美文网首页
Pandas 字符串转日期对象

Pandas 字符串转日期对象

作者: 7ming | 来源:发表于2019-07-10 17:25 被阅读0次

问题描述:

dataframe中有类似 20190101 格式的日期数据,想处理成pandas可识别的日期格式

解决

日期

df['date_formated']=pd.to_datetime(df['date_to_format'],format='%Y%m%d',errors='ignore')

时间

df['date_formated']=pd.to_datetime(df['date_to_format'],format='%Y-%m-%d %H:%M:%S',errors='ignore')

提取

df['hour']=df['date_formated'].dt.hour

相关文章

网友评论

      本文标题:Pandas 字符串转日期对象

      本文链接:https://www.haomeiwen.com/subject/vcohkctx.html