I saw a primitive version of this question here
but i my dataframe has diffrent names and i want to calculate separately for them
   A   B   C
0  a   3   5
1  a   6   9
2  b   3   8
3  b  11  19
i want to groupby A and then find diffence between alternate B and C.something like this
   A   B   C   dA
0  a   3   5   6
1  a   6   9  NaN
2  b   3   8  16
3  b  11  19  NaN
i tried doing
df['dA']=df.groupby('A')(['C']-['B'])
df['dA']=df.groupby('A')['C']-df.groupby('A')['B']
none of them helped what mistake am i making?
 
    