1 回答
TA贡献1796条经验 获得超7个赞
对于时差的计算,这可能会对您有所帮助。但是,您还需要根据重复案例应用您的条件。
# Make df sequential in ["Name", "Last name", "Task"]
df.sort_values(["Name", "Last name", "Task"], inplace=True)
# Compute time difference
temp = df['Entrance time'] - df['Entrance time'].shift()
# converts the difference in terms of minutes (taking into account absolute values)
df['diff_mins'] = temp.abs() /np.timedelta64(1,'m')
输出:
2 2 2000-01-01 00:04:30 Bob Conrad 2 Maintenance nan
6 6 2000-01-02 00:04:30 Bob Conrad 2 Maintenance 1440
1 1 2000-01-01 00:04:30 John Fischer 1 Development 1440
0 0 2000-01-01 00:00:00 John Fischer 1 Maintenance 4.5
4 4 2000-01-01 00:09:30 John Fischer 1 Maintenance 9.5
5 5 2000-01-01 00:15:30 John Fischer 1 Maintenance 6
3 3 2000-01-01 00:10:00 Mary Smith 3 Multitasking 5.5
7 7 2000-01-02 00:10:00 Mary Smith 3 Multitasking 1440
添加回答
举报