>>> df1 = pd.melt(df, value_vars=['Val1', 'Val2', 'Val3', 'Val4'],
... id_vars=['Statistic', 'Ref'], var_name='Values')
>>> df1.pivot_table(values='value', rows=['Ref', 'Values'], cols='Statistic')
Statistic Mean Std
Ref Values
0 Val1 0 0.1
Val2 1 0.1
Val3 2 0.1
Val4 3 0.1
1 Val1 0 0.1
Val2 1 0.1
Val3 2 0.1
Val4 3 0.1
2 Val1 0 0.1
Val2 1 0.1
Val3 2 0.1
Val4 3 0.1
[12 rows x 2 columns]
if you do not want to have MultiIndex, as indicated above, you can use the method .reset_indexin the last data frame;
source
share