I have found a few related questions but none seem to be doing the trick. I want a similar implementation to this but with the pandas dataframe structure. Below I create sample data from the entire 2016 year, which has 366 rows.
import pandas as pd
import numpy as np
dates=pd.date_range('2016-01-01','2016-12-31')
random_data=np.random.randn(len(dates))
data=pd.DataFrame(random_data,index=dates,columns=['Test'])
I would like to use groupby to get the next 5 days of data every 2 days. Normal groupby does not have overlapping timframes; putting in a groupby of 2 days will give me 183 (366/2) groups that have two days data. Putting a groupby of 5 days will give me around 74 (366/5) groups that have 5 days each. I would like 183 groups that have five days each.
Sorry in advance if this is not clear. Here is what I want:
Test
2016-02-08 1.073696
2016-02-09 1.169865
2016-02-10 1.421454
2016-02-11 -0.576036
2016-02-12 -1.066921
Test
2016-02-10 1.421454
2016-02-11 -0.576036
2016-02-12 -1.066921
2016-02-13 2.639681
2016-02-14 -0.261616
This is what I get with data.groupby(pd.TimeGrouper('2d'))
Test
2016-02-08 1.073696
2016-02-09 1.169865
Test
2016-02-10 1.421454
2016-02-11 -0.576036
Test
2016-02-12 -1.066921
2016-02-13 2.639681
This is what I get with data.groupby(pd.TimeGrouper('5d'))
Test
2016-02-08 0.898029
2016-02-09 -0.905950
2016-02-10 -0.202483
2016-02-11 1.073696
2016-02-12 1.169865
Test
2016-02-13 1.421454
2016-02-14 -0.576036
2016-02-15 -1.066921
2016-02-16 2.639681
2016-02-17 -0.261616