1 回答
TA贡献1807条经验 获得超9个赞
我们可以使用str.zfill和字符串连接pd.to_datetime来构建您的日期时间。
df2['date'] = pd.to_datetime(df2['year'].astype(str)
+ df2['month'].astype(str).str.zfill(2)
+ df2['day'].astype(str).str.zfill(2)
+ ' '
+ df2['time'].astype(str),format='%Y%m%d %H:%M:%S'
)
year month day time date
0 2000 1 1 4:30:59 2000-01-01 04:30:59
1 2000 1 1 0:07:35 2000-01-01 00:07:35
2 2000 1 1 4:51:37 2000-01-01 04:51:37
3 2000 1 1 4:27:56 2000-01-01 04:27:56
4 2000 1 1 2:16:31 2000-01-01 02:16:31
5 2000 1 1 0:37:21 2000-01-01 00:37:21
6 2000 1 1 0:52:57 2000-01-01 00:52:57
7 2000 1 1 3:35:14 2000-01-01 03:35:14
8 2000 1 1 2:41:58 2000-01-01 02:41:58
9 2000 1 1 3:43:02 2000-01-01 03:43:02
10 2000 1 1 3:49:19 2000-01-01 03:49:19
11 2000 1 1 3:03:55 2000-01-01 03:03:55
12 2000 1 1 4:46:01 2000-01-01 04:46:01
13 2000 1 1 1:07:24 2000-01-01 01:07:24
14 2000 1 1 8:29:04 2000-01-01 08:29:04
15 2000 1 1 6:35:21 2000-01-01 06:35:21
16 2000 1 1 6:06:25 2000-01-01 06:06:25
17 2000 1 1 7:10:13 2000-01-01 07:10:13
18 2000 1 1 10:57:24 2000-01-01 10:57:24
19 2000 1 1 7:54:38 2000-01-01 07:54:38
添加回答
举报