I read this post but it I couldn`t understand it: Python pandas cumsum with reset everytime there is a 0
This is my dataframe:
df = pd.DataFrame({'pct':range(10, 20), 'day':[0,1,2,3,4,5,0,1,4,5] })
I want to add another column to the df
that shows the cumsum
of pct
and each time day
is 5, cumsum
resets.
This is my desired outcome:
day pct result
0 0 10 10
1 1 11 21
2 2 12 33
3 3 13 46
4 4 14 60
5 5 15 75
6 0 16 16
7 1 17 33
8 4 18 51
9 5 19 70