Reputation: 402483
Given this dataframe:
C
index
0 9
1 0
2 1
3 5
4 0
5 1
6 2
7 20
8 0
How can I split this into groups such that
[9, 0]
, [1, 5, 0]
, [1, 2, 20, 0]
?The idea is to find all sequences that terminate with 0 and group them together. The sequences can vary in size and and the last sequence may not terminate with 0. The first element will never be 0.
My end result looks something like this:
C_new
9
6
23
Where I find these groups and then sum them.
Upvotes: 1
Views: 64