1 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
對(duì)于時(shí)差的計(jì)算,這可能會(huì)對(duì)您有所幫助。但是,您還需要根據(jù)重復(fù)案例應(yīng)用您的條件。
# 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
添加回答
舉報(bào)