I trying to achieve the same with this line of code:
df['Math/Physic']=df.groupby(['Rank'],sort=False).apply(lambda x:x['Maths']/x['Physics'])--->doesn't work
I am getting this below error:
TypeError: incompatible index of inserted column with frame index
This code below work though. It looks like , the code above not able to fetch value from those columns:
df['Math/Physic']=df.groupby(['Rank'],sort=False).apply(lambda x:10/2])--->works fine
I have tried different variations but not able to get this working. Any help on this will be highly appreciated.