[英]Convert int64 column to datetime column in python
I have a dataframe with one column 'time', which is the object int64
and looks like this:我有一个 dataframe 有一列“时间”,即 object
int64
,如下所示:
time
202003180001043
202003180001044
And which should be converted to a datetime column:并且应该将其转换为日期时间列:
time
2020-03-18 00:01:043
2020-03-18 00:01:044
When I run the command:当我运行命令时:
df['time'] = pd.to_datetime(df['time'], format='%Y%m%d%I%M%S')
I get the error: ValueError: unconverted data remains: 04我收到错误: ValueError:未转换的数据仍然存在:04
How canI include the last numbers?如何包含最后的数字?
Problem is %I
is for hour in 12hours format, so failed.问题是
%I
是 12 小时格式的小时,所以失败了。 Need %H
for hours in 24hours format:需要
%H
以 24 小时格式表示小时数:
df['time'] = pd.to_datetime(df['time'], format='%Y%m%d%H%M%S%f')
print (df)
time
0 2020-03-18 00:01:04.300
1 2020-03-18 00:01:04.400
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.