我有一个数据集,列出了员工和他们完成某些操作的时间戳。它分为三列:雇员、日期、小时。在
我想计算每小时活跃的员工人数。在excel中,我将通过添加第四列EmpFactor
来完成此操作,在该列中我执行COUNTIFS
操作:
=1/COUNTIFS(Name range;Name;Date range;Date;Hour range;Hour)
随后,我可以通过对EmpFactor
列执行SUMIF
来计算在职员工的数量。在
我尝试使用pandas编写EmpFactor
列:
但这不起作用。我广泛地搜索了许多关于SO的话题,但还没有找到合适的答案。在
假设您有这样的数据帧结构:
当然,最好将
Time
作为DateTime
列的一部分。如果你愿意,你可以练习一下:)这种方法相当快:在我的笔记本电脑上,对4700万行进行分组大约需要3分钟。在
从这个数据帧开始:
输出:
^{pr2}$您可以按
Date
和Time
分组并计算员工数:输出:
相关问题 更多 >
编程相关推荐