I have a DATAFRAME which looks like this. I want to substract the cumulative sum of AMOUNT WITH TOTAL_AMOUNT for each ID seperately. so the result must be grouped by ID
ID AMOUNT TOTAL_AMOUNT
110 1250 4000
110 250 4000
110 350 4000
111 985 3500
111 440 3500
111 50 3500
112 1080 4000
112 380 4000
After the calculation, my output should look something like this
ID AMOUNT TOTAL_AMOUNT CALCULATION(new column)**(TOTAL_AMOUNT-CUMSUM(AMOUNT)**
110 1250 4000 2750
110 250 4000 2500
110 350 4000 2150
111 985 3500 2515
111 440 3500 2075
111 50 3500 2025
112 1080 4000 2920
112 380 4000 2540