Within a dataframe, I need to count and sum consecutive row values in column A
into a new column, column B
.
Starting with column A
, the script would count the consecutive runs in 1s
but when a 0
appears it prints the total count in column B
, it then resets the count and continues through the remaining data.
Desired outcome:
A | B
0 0
1 0
1 0
1 0
1 0
0 4
0 0
1 0
1 0
0 2
I've tried using .shift()
along with various if-statements
but have been unsuccessful.