Im trying to do the following: Have a dataframe with columns "Cat" and "Amount". I want to create another column that as long as the values in "Cat" are the same it adds up the differences between the values i and i+1 in the "Amount" column. When the value in "Cat" changes it goes back to 0 and starts again.
Attached an example.