I went through different stackoverflow questions and finally posting it because I couldnt solve one of the issues I am facing. I have a dataframe like below
A B C
group1 group1_c 12
group1 group1_c 12
group1 group1_c 12
group1 group1_c 1
group1 group1_c 12
group1 group1_c 12
I have to match two rows together and whenever the value matches, I cumsum it. To do this,
df['cumul'] = df['C'].eq(df.groupby(['A','B'])['C'].shift(1).ffill()).groupby([df['A'],df['B']).cumsum()
Once I do this,
A B C Cumul
group1 group1_c 12 0
group1 group1_c 12 1
group1 group1_c 12 2
group1 group1_c 1 2
group1 group1_c 12 3
group1 group1_c 12 3
Whereas I want to reset if the condition is not met.Expected solution
A B C Cumul
group1 group1_c 12 0
group1 group1_c 12 1
group1 group1_c 12 2
group1 group1_c 1 0
group1 group1_c 12 0
group1 group1_c 12 1
Please advice Thank you