python - Pandas: index of max value for each group -
my pandas dataframe, df
, looks this:
parameter1 parameter2 value 1 1 0.1 2 0.2 2 1 0.6 2 0.3
value
result of groupby(['parameter1','parameter2']).mean()
on dataframe
. now, can find maximum value of value
each value of parameter1
using
df.max(level='parameter1')
however, need find corresponding value of parameter2
maximum value. seems df.idxmax()
not support level=
, how can instead?
a nice way be
df.unstack().idxmax(axis=1)
unstacking dataframe gives dataframe parameter_1
column index.
Comments
Post a Comment