Python 将int64列转换为时间列

Python 将int64列转换为时间列,python,pandas,datetime,Python,Pandas,Datetime,我有一个带有“时间”列的pandas数据框,它当前看起来像: ab['ZEIT'].unique() array([ 0, 165505, 203355, ..., 73139, 75211, 74244], dtype=int64) array([00:00:00, 16:55:05, 20:33:55, ..., 07:31:39, 07:52:11, 07:42:44], dtype=?) 如何使用hh:mm:ss从中提取德语时间格式,使其基本上看起来像: ab['ZEI

我有一个带有“时间”列的pandas数据框,它当前看起来像:

ab['ZEIT'].unique()
array([     0, 165505, 203355, ...,  73139,  75211,  74244], dtype=int64)
array([00:00:00, 16:55:05, 20:33:55, ..., 07:31:39, 07:52:11, 07:42:44], dtype=?)
如何使用hh:mm:ss从中提取德语时间格式,使其基本上看起来像:

ab['ZEIT'].unique()
array([     0, 165505, 203355, ...,  73139,  75211,  74244], dtype=int64)
array([00:00:00, 16:55:05, 20:33:55, ..., 07:31:39, 07:52:11, 07:42:44], dtype=?)

将值转换为带填充0的字符串后,使用
pd.to_datetime
。然后调用
dt
accessor查看
time

In [12]: pd.to_datetime(df['ZEIT'].astype(str).str.zfill(6), format='%H%M%S').dt.time
Out[12]: 
0    00:00:00
1    16:55:05
2    20:33:55
3    07:31:39
4    07:52:11
5    07:42:44
Name: ZEIT, dtype: object

细节

In [13]: df
Out[13]: 
     ZEIT
0       0
1  165505
2  203355
3   73139
4   75211
5   74244

In [14]: df['ZEIT'].astype(str).str.zfill(6)
Out[14]: 
0    000000
1    165505
2    203355
3    073139
4    075211
5    074244
Name: ZEIT, dtype: object

In [15]: pd.to_datetime(df['ZEIT'].astype(str).str.zfill(6), format='%H%M%S')
Out[15]: 
0   1900-01-01 00:00:00
1   1900-01-01 16:55:05
2   1900-01-01 20:33:55
3   1900-01-01 07:31:39
4   1900-01-01 07:52:11
5   1900-01-01 07:42:44
Name: ZEIT, dtype: datetime64[ns]