【发布时间】:2021-06-18 07:01:59
【问题描述】:
我在数据框中有一列有时间戳,它们的数据类型是对象(字符串):
data_log = pd.read_csv(DATA_LOG_PATH)
print(data_log['LocalTime'])
0 09:38:49
1 09:38:50
2 09:38:51
3 09:38:52
4 09:38:53
...
Name: LocalTime, Length: 872, dtype: object
现在我尝试转换为日期时间:
data_log['LocalTime'] = pd.to_datetime(data_log['LocalTime'], format='%H:%M:%S')
print(data_log['LocalTime'])
0 1900-01-01 09:38:49
1 1900-01-01 09:38:50
2 1900-01-01 09:38:51
3 1900-01-01 09:38:52
4 1900-01-01 09:38:53
...
Name: LocalTime, Length: 872, dtype: datetime64[ns]
如何在此处删除该日期?我只想要我指定格式的时间,但它将 1900-01-01 添加到每一行。
【问题讨论】: