我想在python数据框中转换一列。列的类型为object。
来自20年12月21日09:20 PM
至此2020-12-21 21:20:00:00.000
df["column"] = pd.to_datetime(df["column"])
如果需要更具体的格式,请编辑您的问题并加注释,以便我可以相应地调整答案。
如果您想将其转换为dtype: datetime64[ns]
然后使用:df["column"] = pd.to_datetime(df["column"])
或指定您的格式
pd.to_datetime(pd.Series(['05/23/2005']), format="%m/%d/%Y")
Out[12]:
0 2005-05-23
dtype: datetime64[ns]
一旦您可以将pandas.Series.dt.strftime
用作所需的任何格式的字符串