【发布时间】:2019-12-18 05:44:47
【问题描述】:
我有这个数据框:
ID Date Received
000 2018-01-01 00:00:00+00:00 True
2018-01-01 06:24:44+00:00 True
2018-01-03 16:24:45+00:00 False
2018-01-13 20:00:00+00:00 True
2018-01-13 23:00:00+00:00 True
2018-01-25 22:30:55+00:00 True
2018-01-26 00:30:55+00:00 False
111 2018-01-01 12:00:00+00:00 True
2018-01-02 15:00:45+00:00 True
2018-01-04 00:00:00+00:00 True
有没有办法在 7 天内对 Received 列中的 True 值的数量进行滚动窗口计数并按 ID 分组?我尝试使用 df.rolling('7D').count() 但它返回错误。
我一直在寻找这样的东西:
ID Date range Count
000 2018-01-01 00:00:00+00:00 - 2018-01-07 00:00:00+00:00 2
2018-01-08 20:00:00+00:00 - 2018-01-14 00:00:00+00:00 2
2018-01-15 22:30:55+00:00 - 2018-01-21 20:00:00+00:00 0
2018-01-22 22:30:55+00:00 - 2018-01-28 20:00:00+00:00 1
111 2018-01-01 00:00:00+00:00 - 2018-01-07 00:00:00+00:00 3
【问题讨论】:
标签: python pandas time-series rolling-computation