I have the following pandas dataframe,
status1 status2 location1 datetime1 grouping service capacity
0 xx xx xx 01-01-2020 11:50:00 xx xx 150
1 xx xx xx 01-01-2020 11:57:00 xx xx 200
2 xx xx xx 01-01-2020 11:59:00 xx xx 200
3 xx xx xx 01-01-2020 13:59:00 xx xx 200
...
x xx xx xx 01-02-2020 13:59:00 xx xx 300
x xx xx xx 01-03-2020 13:04:00 xx xx 300
...
x xx xx xx 07-03-2021 13:04:00 xx xx 400
x xx xx xx 07-03-2021 13:04:00 xx xx 300
x xx xx xx 07-03-2021 13:04:00 xx xx 300
I want to sum up the capacities for each week on a rolling basis.
For for example I want
WeekStartingSunday countofstatus1 sumofcapacity
0 1 50 3000
1 2 30 2000
2 3 ... ...
3 4 ... ...
...
So week 1 contains the sum of all the dates within the first week of 2020. The week would be startingSunday. I also want to create tables for other days like Monday Tuesday etc.
I tried df.groupby('capacity').rolling(7).sum() but it just sums up every 7 rows i think.
I also tried,
group = pd.pivot_table(df,columns='capacity', index='datetime1')
group2 = group.resample('D').sum().rolling(7).sum()
group2.sort_index().head(15)
But it looks like this,
capacity 1.0 2.0 2.25 2.40 3.0....
datetime1
2020-01-01 NaN NaN NaN NaN NaN ...
2021-01-02 NaN NaN NaN NaN NaN ...
...
2021-01-07 322.1 326.5 117 0.0 275.2 ...
...
Can this be done in pandas ?