I have a simple df like this:
data
0 0
1 0
2 1
3 1
4 0
5 0
6 1
7 1
8 1
9 1
I am interested in counting the number of times 1 consecutively occurs, and then creating a column assigning that value to each row in the chunk. It should look like this:
data count
0 0 0
1 0 0
2 1 2
3 1 2
4 0 0
5 0 0
6 1 4
7 1 4
8 1 4
9 1 4
Is there a simple pandas way to do this?