I'm not quite clear on how bin-membership in DataFrame.resample
is determined.
Example/actual output:
>>> df = pd.DataFrame(index=pd.date_range(start='2021-04-21 01:00:00', end='2021-04-28 01:00', freq='1d'), data=[1]*8)
>>> df
0
2021-04-21 01:00:00 1
2021-04-22 01:00:00 1
2021-04-23 01:00:00 1
2021-04-24 01:00:00 1
2021-04-25 01:00:00 1
2021-04-26 01:00:00 1
2021-04-27 01:00:00 1
2021-04-28 01:00:00 1
>>> df.resample(rule='7d', origin='2021-04-29 00:00:00', closed='right', label='right').sum()
0
2021-04-22 2
2021-04-29 6
Expected output:
0
2021-04-22 1
2021-04-29 7
Reasoning:
I expected pandas to create the two bins
(2021-04-15 00:00:00, 2021-04-22 00:00:00]
(2021-04-22 00:00:00, 2021-04-29 00:00:00]
and the timestamp 2021-04-21 01:00:00
to fall into the first bin, while 2021-04-22 01:00:00
and the remaining timestamps should fall into the second bin.
edit: I just realized that using 24*7=168 hours instead of 7 days yields the expected result. Why?!
>>> df.resample(rule='168h', origin='2021-04-22 00:00:00', closed='right', label='right').sum()
0
2021-04-22 1
2021-04-29 7
I'm using pandas 1.3.5