I have a multi-index dataframe as shown below.
+-------+----+------+
| | | %age |
+-------+----+------+
| Group | Id | |
| 0 | 18 | 75 |
| 0 | 30 | 12 |
| 0 | 42 | 13 |
| 1 | 18 | 12 |
| 1 | 30 | 75 |
| 1 | 42 | 13 |
| 2 | 18 | 13 |
| 2 | 30 | 12 |
| 2 | 42 | 75 |
+-------+----+------+
I want to get the max values from each of the group, but as opposed to many other questions on SO, also want to show all the index-level columns. like this:
+-------+----+------+
| | | %age |
| Group | Id | |
| 0 | 18 | 75 |
| 1 | 30 | 75 |
| 2 | 42 | 75 |
+-------+----+------+
I tried this answer from here
df1 = df_pct.reset_index(level=1, drop=True)
mask = df1.index.isin(df1.groupby(level=[0])['%age'].idxmax())
df_pct[mask]
But I am getting an output that displays the whole dataframe