I'm having trouble coming up with a way to perform a cumulative sum on a column and creating a flag once it hits a certain value.
So given a dataframe:
df = pd.DataFrame([[5,1],[6,1],[30,1],[170,0],[5,1],[10,1]],columns = ['a','b'])
a b
0 5 1
1 6 1
2 30 1
3 170 0
4 5 1
5 10 1
For column A, I want to perform the cumulative sum and set the "Flag" column value to 1 if that max value is reached. Upon reaching that max value, it will reset to 0. In this case, the max value is 40. Any cumulative sum over 40 will trigger the reset
Desired Output
a b Flag
0 5 1 0
1 11 1 0
2 41 1 1
3 170 0 1
4 5 1 0
5 15 1 0
Any help would be appreciated!