我有以下数据帧
padel start_time end_time duration
38 Padel 10 08:00:00 09:00:00 60
40 Padel 10 10:00:00 11:30:00 90
42 Padel 10 10:30:00 12:00:00 90
44 Padel 10 11:00:00 12:30:00 90
46 Padel 10 11:30:00 13:00:00 90
49 Padel 10 16:00:00 17:30:00 90
51 Padel 10 16:30:00 18:00:00 90
53 Padel 10 17:00:00 18:30:00 90
55 Padel 10 17:30:00 19:00:00 90
57 Padel 10 18:00:00 19:30:00 90
59 Padel 10 18:30:00 20:00:00 90
61 Padel 10 19:00:00 20:30:00 90
63 Padel 10 19:30:00 21:00:00 90
65 Padel 10 20:00:00 21:30:00 90
67 Padel 10 20:30:00 22:00:00 90
我想在两者之间选择最长的时间跨度。我想要的输出应该是这样的
padel start_time end_time duration
38 Padel 10 08:00:00 09:00:00 60
40 Padel 10 10:00:00 13:00:00 180
49 Padel 10 16:00:00 22:00:00 360
我不在乎持续时间。我能做到。但我将如何合并重叠的时间跨度。 谢谢
start_time
是上面行的greater than
{shift()
创建组李>fillna
和'24:00:00'
来返回第一个值的'True',因为一天内任何值都不能超过24小时。这是因为NaN
是第一行中带有shift()
的输出,如果我们不这样做,它将返回False
李>boolean
序列(即分别为1
和0
),因此只需取cumsum
的累积和李>grp
对象,我们可以将其包含在groupby
中李>带有输入数据帧的完整代码
我想不出一个简单的方法来做这件事,所以我就用for循环。尚未测试此代码,但类似于:
相关问题 更多 >
编程相关推荐