更新时间:2023-02-03 15:18:43
The easiest way is to use to_datetime
:
df['col'] = pd.to_datetime(df['col'])
它还为欧洲时间提供了dayfirst
参数(但请注意这并不严格).
It also offers a dayfirst
argument for European times (but beware this isn't strict).
这里正在起作用:
In [11]: pd.to_datetime(pd.Series(['05/23/2005']))
Out[11]:
0 2005-05-23 00:00:00
dtype: datetime64[ns]
您可以传递特定的格式:
In [12]: pd.to_datetime(pd.Series(['05/23/2005']), format="%m/%d/%Y")
Out[12]:
0 2005-05-23
dtype: datetime64[ns]