在python pandas中,如何将此格式化的日期字符串转换为datetime

cla*_*nn1 3 python string-to-datetime pandas

我尝试了几种使用方法to_datetime,但到目前为止我只能将它作为"对象"返回dtype

pd.to_datetime(pd.Series(['28Dec2013 19:23:15']),dayfirst=True)
Run Code Online (Sandbox Code Playgroud)

该命令的返回值为:

0    28Dec2013 19:23:15
dtype: object
Run Code Online (Sandbox Code Playgroud)

And*_*ndy 5

您可以将format参数传递给to_datetime函数.

>>> import pandas as pd
>>> df = pd.to_datetime(pd.Series(['28Dec2013 19:23:15']),format="%d%b%Y %H:%M:%S",dayfirst=True)
>>> df
0   2013-12-28 19:23:15
dtype: datetime64[ns]
Run Code Online (Sandbox Code Playgroud)