df['total'] = (df.DR - df.CR).cumsum()
is giving:
...
Name DR CR total
303 B3 46.80 0.00 46682.07
304 B3 45.20 0.00 46727.27
395 BS1 0.00 10.37 47905.31
396 BS2 0.00 87.00 47818.31
397 C 0.00 482.10 47336.21
399 C 20.00 0.00 47356.21
However I would like the cumsum to "restart" whenever the "Name"
column (B3,BS1,C) changes to a different value.
So the desired result is:
Name DR CR total
303 B3 46.80 0.00 46.80
304 B3 45.20 0.00 1.60
395 BS1 0.00 10.37 -10.37
396 BS2 0.00 87.00 -97.37
397 C 0.00 482.10 -482.10
399 C 20.00 0.00 -462.10
I am new to pandas. Thanks for your help
I have tried things like, but not working:
df['total'] = df.groupby('GL')[(df.DR - df.CR)].cumsum()