My Pandas DataFrame, df, looks like this:
parameter1   parameter2   value
1            1            0.1
             2            0.2
2            1            0.6
             2            0.3
value is the result of a groupby(['parameter1','parameter2']).mean() on another DataFrame. Now, I can find the maximum value of value for each value of parameter1 using
df.max(level='parameter1')
However, I need to find the corresponding value of parameter2 for this maximum value. It seems df.idxmax() does not support level=, so how can I do this instead?
A nice way would be
df.unstack().idxmax(axis=1)
Unstacking the dataframe gives a dataframe with parameter_1 as the column index. 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With