如何计算每个员工每天每次进出的时间差总和?
我正在使用这个数据框,每个员工都有一个唯一的ID,在E/X列中,6代表他进入的时间,1代表他离开的时间
Emp E/X DateTime Date Time
107 6 2022-01-04 10:04:18 0 2022-01-04 10:04:18
107 6 2022-01-04 11:32:52 0 2022-01-04 11:32:52
107 6 2022-01-04 11:39:59 0 2022-01-04 11:39:59
107 1 2022-01-04 12:05:26 0 2022-01-04 12:05:26
107 6 2022-01-04 18:02:18 0 2022-01-04 18:02:18
107 6 2022-01-04 18:30:38 0 2022-01-04 18:30:38
107 1 2022-01-04 19:06:58 0 2022-01-04 19:06:58
107 1 2022-01-05 12:22:10 0 2022-01-05 12:22:10
107 6 2022-01-05 19:22:15 0 2022-01-05 19:22:15
122 1 2022-01-03 08:57:40 0 2022-01-03 08:57:40
122 6 2022-01-03 12:49:33 0 2022-01-03 12:49:33
122 1 2022-01-03 13:22:28 0 2022-01-03 13:22:28
122 6 2022-01-03 16:29:51 0 2022-01-03 16:29:51
122 1 2022-01-03 16:40:06 0 2022-01-03 16:40:06
我想知道是否可以计算员工每天的工作量和更改 E/X 列,以便每天都有连续的输入/输出,因为有时会出现错误,有时会连续出现多个条目,例如我要取出前两行并将第二行更改为退出:
Emp E/X DateTime Date Time
107 6 2022-01-04 10:04:18 0 2022-01-04 10:04:18
107 1 2022-01-04 11:32:52 0 2022-01-04 11:32:52
122 6 2022-01-03 08:57:40 0 2022-01-03 08:57:40
122 1 2022-01-03 12:49:33 0 2022-01-03 12:49:33
122 6 2022-01-03 13:22:28 0 2022-01-03 13:22:28
122 1 2022-01-03 16:29:51 0 2022-01-03 16:29:51 this line is going to be deleted
122 1 2022-01-03 16:40:06 0 2022-01-03 16:40:06
所需结果:
Emp E/X DateTime Date Time
107 6 2022-01-04 10:04:18 0 2022-01-04 10:04:18
107 1 2022-01-04 11:32:52 0 2022-01-04 11:32:52
107 6 2022-01-04 11:39:59 0 2022-01-04 11:39:59
107 1 2022-01-04 12:05:26 0 2022-01-04 12:05:26
107 6 2022-01-04 18:02:18 0 2022-01-04 18:02:18
107 1 2022-01-04 19:06:58 0 2022-01-04 19:06:58
107 6 2022-01-05 12:22:10 0 2022-01-05 12:22:10
107 1 2022-01-05 19:22:15 0 2022-01-05 19:22:15
122 6 2022-01-03 08:57:40 0 2022-01-03 08:57:40
122 1 2022-01-03 12:49:33 0 2022-01-03 12:49:33
122 6 2022-01-03 13:22:28 0 2022-01-03 13:22:28
122 1 2022-01-03 16:40:06 0 2022-01-03 16:40:06
E/X 是固定的,我想计算每个员工每天 6 和 1 之间的每个差异的总和
期望结果:
EMP Date WorkHours
4 107 2022-01-03 2
5 107 2022-01-04 8
6 122 2022-01-03 4
i'm using this dataframe , each employee have a unique ID and in column E/X , 6 represent the time he entered and 1 represent the time he left
Emp E/X DateTime Date Time
107 6 2022-01-04 10:04:18 0 2022-01-04 10:04:18
107 6 2022-01-04 11:32:52 0 2022-01-04 11:32:52
107 6 2022-01-04 11:39:59 0 2022-01-04 11:39:59
107 1 2022-01-04 12:05:26 0 2022-01-04 12:05:26
107 6 2022-01-04 18:02:18 0 2022-01-04 18:02:18
107 6 2022-01-04 18:30:38 0 2022-01-04 18:30:38
107 1 2022-01-04 19:06:58 0 2022-01-04 19:06:58
107 1 2022-01-05 12:22:10 0 2022-01-05 12:22:10
107 6 2022-01-05 19:22:15 0 2022-01-05 19:22:15
122 1 2022-01-03 08:57:40 0 2022-01-03 08:57:40
122 6 2022-01-03 12:49:33 0 2022-01-03 12:49:33
122 1 2022-01-03 13:22:28 0 2022-01-03 13:22:28
122 6 2022-01-03 16:29:51 0 2022-01-03 16:29:51
122 1 2022-01-03 16:40:06 0 2022-01-03 16:40:06
I was wondering if it was possible to calculate how much the employee worked each day and change the E/X column so that each day has a successive in/out because it has errors sometimes there's multiple entries successively for exemple im gonna take the first two rows and change the second one into exit :
Emp E/X DateTime Date Time
107 6 2022-01-04 10:04:18 0 2022-01-04 10:04:18
107 1 2022-01-04 11:32:52 0 2022-01-04 11:32:52
122 6 2022-01-03 08:57:40 0 2022-01-03 08:57:40
122 1 2022-01-03 12:49:33 0 2022-01-03 12:49:33
122 6 2022-01-03 13:22:28 0 2022-01-03 13:22:28
122 1 2022-01-03 16:29:51 0 2022-01-03 16:29:51 this line is going to be deleted
122 1 2022-01-03 16:40:06 0 2022-01-03 16:40:06
desired result :
Emp E/X DateTime Date Time
107 6 2022-01-04 10:04:18 0 2022-01-04 10:04:18
107 1 2022-01-04 11:32:52 0 2022-01-04 11:32:52
107 6 2022-01-04 11:39:59 0 2022-01-04 11:39:59
107 1 2022-01-04 12:05:26 0 2022-01-04 12:05:26
107 6 2022-01-04 18:02:18 0 2022-01-04 18:02:18
107 1 2022-01-04 19:06:58 0 2022-01-04 19:06:58
107 6 2022-01-05 12:22:10 0 2022-01-05 12:22:10
107 1 2022-01-05 19:22:15 0 2022-01-05 19:22:15
122 6 2022-01-03 08:57:40 0 2022-01-03 08:57:40
122 1 2022-01-03 12:49:33 0 2022-01-03 12:49:33
122 6 2022-01-03 13:22:28 0 2022-01-03 13:22:28
122 1 2022-01-03 16:40:06 0 2022-01-03 16:40:06
and once the E/X is fixed i want to calculate the sum of every difference between 6 and 1 per employee for each day
Desired Result:
EMP Date WorkHours
4 107 2022-01-03 2
5 107 2022-01-04 8
6 122 2022-01-03 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将使用我自己的测试数据并假设它已经干净,即交替开始/结束日期时间
setup
df
看起来像这样解决方案
这将使用一个名为 piso 的包(pandas 间隔设置操作)。特别是,它将遵循 piso 的最后一个示例.coverage
hours_worked
看起来像这样:注意:我是 piso 的创建者。如果您有任何反馈或问题,请随时与我们联系。
Going to use my own test data and assume it is already clean, i.e. alternating start/end datetimes
setup
df
looks like thissolution
This will use a package called piso (pandas interval set operations). In particular it will follow the last example of piso.coverage
hours_worked
looks like this:note: I am the creator of piso. Please feel free to reach out with feedback or questions if you have any.