【发布时间】:2019-08-03 06:02:30
【问题描述】:
给定一个事件的开始时间和结束时间,我想指定它们所属的小时(开始时间)的相应持续时间:
例如,如果我有一个数据框:
event start_time end_time
a 8:00 8:30
b 8:49 10:22
在这种情况下,hour(start_time) = 8,与第一行一样被分配 30 分钟。 但是,如果 start_time 和 end_time 的小时数不像第二行那样相等, 那么我想将 start_time 和 end_time 拆分如下:
event start_time end_time hour(start_time) duration
a 8:00 8:30 8 30
b 8:49 9:00 8 11
b 9:00 10:00 9 60
b 10:00 10:22 10 22
在 pandas 中是否有一种简单的方法来实现这一点?
【问题讨论】:
-
Is there a straightforward way to accomplish this in pandas?- 我不认为,在熊猫中不存在此功能。那么你可以将你的循环解决方案添加到问题中吗?