I have a dataframe in Pandas like the above:
A B C
0 1 10 43
1 2 12 34
2 1 9 57
3 2 7 47
4 1 6 30
5 2 10 31
What I would like to do is to calculate the differences of every two rows according to column A (essentially get the differences of all the other columns when A=1 - A=2). So, I would like to come up with something like this:
B C
0 -2 9
1 2 10
2 -4 -1
I know about the diff() function but it doesn't seem to do the thing I want. Is there a way?