I have a dataframe that looks like this:
| finalcheck |
|---|
| False |
| True |
| True |
| True |
| False |
| True |
I want to create another column in this dataframe which gives me a cumulative sum based on finalcheck variable like so:
| finalcheck | position |
|---|---|
| False | 1 |
| True | 2 |
| True | 3 |
| True | 4 |
| False | 1 |
| True | 2 |
I have tried multiple ways of achieving this but the closest I could get was by using a groupby with the cumsum function in pandas:
df['position'] = df.groupby((df.finalcheck).cumsum())
This did not give me the desired output. Could you help me identify where I am going wrong?