Subtract on Pandas DF

Viewed 43

image

I wanted to subtract all CR with DR row for each account no separately.

Expected output :

account_no | REMIT

10051056346 | 7,04,215
10051059074 | 9,39,395

1 Answers

You can use the xs selector:

out = (df
 .xs('CR', level='type')
 .sub(df.xs('DR', level='type'))
)
Related