pandas python pandas用月份名称解析日期时间字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32332984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 23:50:45  来源:igfitidea点击:

python pandas parse datetime string with months names

pythonparsingdatetimepandas

提问by sh1ng

Can someone point me to a format or a code snippet to parse date in format like

有人可以指出我的格式或代码片段来解析格式的日期,例如

04SEP12:00:00:00

That %dd%mm%YY:%HH:%MM:%SSdoesn't work.

%dd%mm%YY:%HH:%MM:%SS行不通。

回答by EdChum

Use format string: '%d%b%y:%H:%M:%S'and pass this as the format for to_datetime, you can find the format options in the docs:

使用格式字符串:'%d%b%y:%H:%M:%S'并将其作为格式传递给to_datetime,您可以在文档中找到格式选项:

In [73]:

pd.to_datetime('04SEP12:00:00:00', format='%d%b%y:%H:%M:%S')
Out[73]:
Timestamp('2012-09-04 00:00:00')

回答by kevin

Another way is simply do:

另一种方法是简单地做:

pd.to_datetime("May 15, 2016", infer_datetime_format=True)

>>>Timestamp('2016-05-15 00:00:00')

回答by kevin

As another example,

再举一个例子,

pd.to_datetime("May 15, 2016", format="%b %d, %Y")
>>>Timestamp('2016-05-15 00:00:00')

Use %b for the month names.

使用 %b 作为月份名称。