1

My dataframe is a multi index data frame for columns, I would like to have maximum for level 1 for each row, something like this.

        max_values = pivot_df.max(axis=0, level=1)

For example:

A     B 
c  d  e   f
2  4  3   2
4  1  2   6

Request:

A   B
4   3
4   6
Ahmad
  • 8,811
  • 11
  • 76
  • 141
  • Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Aug 21 '23 at 15:45
  • @itprorh66 I added – Ahmad Aug 21 '23 at 17:08

1 Answers1

1

Use groupby first then max:

max_values = pivot_df.groupby(level=0, axis=1).max()
print(max_values)

# Output
   A  B
0  4  3
1  4  6
Corralien
  • 109,409
  • 8
  • 28
  • 52