calculation between groups in a pandas multiindex dataframe,df['ratio'] = df.groupby(level=0)[3].transform(lambda x: x[0] / x[1])