pandas格式化str为时间,pandas将int转化为str

Posted rvin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pandas格式化str为时间,pandas将int转化为str相关的知识,希望对你有一定的参考价值。

code_300[‘HISTORY_DATE‘] = code_300[‘HISTORY_DATE‘].map(str)
code_300[‘HISTORY_DATE‘] = pd.to_datetime(code_300[‘HISTORY_DATE‘], format=‘%Y-%m-%d‘)

1.map函数可以为series所用,pandas可以用applymap函数适用于整个pandas,博客参考:https://blog.csdn.net/u010814042/article/details/76401133/
2.to_datetime函数可以将pandas的20180902这种直接格式化为日期格式,博客参考:https://blog.csdn.net/mhywoniu/article/details/78513935



以上是关于pandas格式化str为时间,pandas将int转化为str的主要内容,如果未能解决你的问题,请参考以下文章

pandas使用pd.DatetimeIndex函数将混合格式的日期数据数据转化为时间索引数据DatetimeIndex通过index参数为Series数据指定时间对象索引

将列转换为时间戳 - Pandas Dataframe

pandas使用pd.DatetimeIndex函数将混合格式的日期数据(包含字符串datetime对象pd.Timestamp)数据转化为时间索引数据DatetimeIndex

pandas使用to_datetime函数将时间字符串转化为时间对象format参数定义输入时间字符串的格式(format=‘%m/%d/%Y %H:%M‘)

pandas将dataframe中日期字符串数据列和时间字符串数据列合并成完整时间字符串并使用to_datetime将字符串格式转化为时间格式

一文速学-Pandas中DataFrame转换为时间格式数据与处理