0

I have a pandas DF as follows: enter image description here

What I want to get is a 1 Column df that contains the name of the column of the maximum value of the row, or the order number of that column. (see red circles in the pic)

Any suggestion?

here the data for copy and paste:

matrix = np.array([[0.92234683, 0.94209485, 0.90884652, 0.99763808],
       [0.86166401, 0.96755855, 0.9243107 , 0.94240756],
       [0.85457367, 0.9169915 , 0.95042024, 0.90661279],
       [0.83972504, 0.93902909, 0.91985442, 0.93765059],
       [0.84373323, 0.87762977, 0.91005636, 0.88525626]])

thanks

JFerro
  • 3,203
  • 7
  • 35
  • 88

2 Answers2

1

Use idxmax:

df = pd.DataFrame(matrix, columns=['Y_clm1', 'Y_clm2', 'Y_clm3', 'Y_clm4'])
>>> df.idxmax(axis=1)
0    Y_clm4
1    Y_clm2
2    Y_clm3
3    Y_clm2
4    Y_clm3
dtype: object
Corralien
  • 109,409
  • 8
  • 28
  • 52
0

use max

df = pd.DataFrame(matrix)
max(df) == 3

max(df) corresponds to Y_clm4

Savvii
  • 480
  • 4
  • 9