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
添加回答
舉報