在我的csv文件中,列的值为1/1/2022 12:34:16 a但是,单元格中的值仅显示34:16.02 (分钟、秒和毫秒)。
我想将该列转换为1/1/2022 12:34:16 12格式的datetime格式,这样我就可以减去另一个类似的列来获得时间差。
我尝试过使用strptime,但是它给了我一个错误,即“值必须是字符串格式的”。因此,我试图将这些值转换为“str”,但这仍然不起作用。
df‘’start‘=df’‘start’..astype(“str”)
df‘’start‘=datetime.strptime(df’‘start’,'%d/%m/%y %H:%M:%S')
有人能帮忙吗?非常感谢!
发布于 2022-08-26 04:25:38
尝试以下几点:
date_string = str(df['start'])
format = '%d/%m/%Y %H:%M:%S%p'
df['start'] = datetime.strptime(date_string, format)https://stackoverflow.com/questions/73496040
复制相似问题