演示:
样品DF:In [32]: df = pd.DataFrame({'Time':pd.date_range('2017-01-01 00:00:01', freq='3S', periods=15)})
In [33]: df
Out[33]:
Time
0 2017-01-01 00:00:01
1 2017-01-01 00:00:04
2 2017-01-01 00:00:07
3 2017-01-01 00:00:10
4 2017-01-01 00:00:13
5 2017-01-01 00:00:16
6 2017-01-01 00:00:19
7 2017-01-01 00:00:22
8 2017-01-01 00:00:25
9 2017-01-01 00:00:28
10 2017-01-01 00:00:31
11 2017-01-01 00:00:34
12 2017-01-01 00:00:37
13 2017-01-01 00:00:40
14 2017-01-01 00:00:43
解决方案:
^{pr2}$
结果:In [35]: df
Out[35]:
Time label
0 2017-01-01 00:00:01 0
1 2017-01-01 00:00:04 0
2 2017-01-01 00:00:07 0
3 2017-01-01 00:00:10 0
4 2017-01-01 00:00:13 1
5 2017-01-01 00:00:16 1
6 2017-01-01 00:00:19 1
7 2017-01-01 00:00:22 1
8 2017-01-01 00:00:25 2
9 2017-01-01 00:00:28 2
10 2017-01-01 00:00:31 2
11 2017-01-01 00:00:34 2
12 2017-01-01 00:00:37 3
13 2017-01-01 00:00:40 3
14 2017-01-01 00:00:43 3