germanjke
germanjke

Reputation: 519

Column names corresponding to maximum value

i have dataframe df

         0.0         1.0         2.0         3.0         4.0         5.0
0   0.537592    0.255088    0.102097    0.062989    0.024679    0.006685
1   0.063914    0.077319    0.173972    0.276244    0.121987    0.021594

i need take maximum in every row. so maximum in first line is 0.537592 [column name 0.0], in second line it's 0.276244 [colum name 3.0]

so i need df like

        label        
0        0.0
1        3.0

how i can make this? tried something like subs.loc[subs['0.0'] == subs['0.0'].max(axis=1)] but it doesn't help

Upvotes: 0

Views: 27

Answers (1)

yatu
yatu

Reputation: 88236

You want idxmax for this:

df.idxmax(axis=1).to_frame(name='Label')

   Label
0   0.0
1   3.0

Upvotes: 2

Related Questions