将 pandas 列转换为DateTime [英] Convert Pandas Column to DateTime
本文介绍了将 pandas 列转换为DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个以字符串格式导入的大熊猫DataFrame中有一个字段。
它应该是一个datetime变量。
如何将其转换为datetime列,然后根据日期过滤。
I have one field in a pandas DataFrame that was imported as string format. It should be a datetime variable. How do I convert it to a datetime column and then filter based on date.
示例:
- DataFrame名称: raw_data
- 列名称: Mycol
- 值
列中的格式:'05SEP2014:00:00:00.000'
- DataFrame Name: raw_data
- Column Name: Mycol
- Value Format in Column: '05SEP2014:00:00:00.000'
推荐答案
使用 to_datetime
功能,指定格式以匹配您的数据。
Use the to_datetime
function, specifying a format to match your data.
raw_data['Mycol'] = pd.to_datetime(raw_data['Mycol'], format='%d%b%Y:%H:%M:%S.%f')
这篇关于将 pandas 列转换为DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文