将时间列(对象类型)转换为日期时间格式

时间:2020-04-22 04:52:34

标签: python python-datetime

我有HH:MM:SS对象类型的单独列。我想将对象类型转换为DateTime格式。遇到以下错误。 enter image description here

数据集时间列[“ ACCIDENT_TIME]: enter image description here

2 个答案:

答案 0 :(得分:1)

您也可以尝试以下方法:

import pandas as pd
df['col_name'] = pd.to_datetime(df['col_name'], errors='coerce')

答案 1 :(得分:0)

如果要更改列的dtype,可以按以下方式操作:

df ['col_name'] = df ['col_name']。astype('datetime64 [ns]')