I have a dataframe like this:
Name_A ¦ date1 ¦ 1
Name_A ¦ date2 ¦ 0
Name_A ¦ date3 ¦ 1
Name_A ¦ date4 ¦ 1
Name_A ¦ date5 ¦ 1
Name_B ¦ date6 ¦ 1
Name_B ¦ date7 ¦ 1
Name_B ¦ date8 ¦ 0
Name_B ¦ date9 ¦ 1
And I would like to get this:
Name_A ¦ date1 ¦ 1
Name_A ¦ date2 ¦ 0
Name_A ¦ date3 ¦ 1
Name_A ¦ date4 ¦ 2
Name_A ¦ date5 ¦ 3
Name_B ¦ date6 ¦ 1
Name_B ¦ date7 ¦ 2
Name_B ¦ date8 ¦ 0
Name_B ¦ date9 ¦ 1
Basically I want to get the cumulative sum of consecutive 1s. If the name changes or there's a 0, it should start the counting from 0 again.
Any ideas/suggestions? Thanks.