在处理一个问题时,我用python编写了以下数据帧
week hour week_hr store_code baskets
0 201616 106 201616106 505 0
1 201616 107 201616107 505 0
2 201616 108 201616108 505 0
3 201616 109 201616109 505 18
4 201616 110 201616110 505 0
5 201616 106 201616108 910 0
6 201616 107 201616106 910 0
7 201616 108 201616107 910 2
8 201616 109 201616108 910 3
9 201616 110 201616109 910 10
这里“hour”变量是“weekday”和“hour of shop”的concat,例如weekday是monday=1,hour of shop是6am,那么hour variable=106,同样的,cal_hr是一个周和小时的concat。我想得到那些我认为没有篮框趋势的行,即滚动3周的0篮数。在上面的例子中,我只得到前3行。i、 e.对于存储505,从106到108有1个篮子的连续循环。但我不想要第4、5、6行,因为即使连续3个小时有0个篮子,但这些小时实际上不是连续的。110->;106->;107。对于连续的小时数,它们应该在106-110的范围内。基本上,我想要所有的商店和相应的行,如果它有0篮子连续3小时在任何一天。虚拟输出
^{pr2}$我可以在python中使用pandas和loops来完成这个任务吗?数据集需要按存储和小时进行排序。完全不熟悉python(
执行以下操作:
现在,您可以将组设置为连续,并根据需要进行过滤。在
不需要循环!在
您可以解决:
代码:
相关问题 更多 >
编程相关推荐