0

I have a dataframe where the first column is time and other columns describe some characteristics. I would like to modify it so that for every time moment it prints the name of the column which is the biggest for that row:

 time  a  b  c  d
 0     4  8  3  7
 1     3  7  1  8
 2     1  0  9  2

 time  
 0     b
 1     d
 2     c
Blazej Kowalski
  • 367
  • 1
  • 6
  • 16
  • Possible duplicate of [Find the column name which has the maximum value for each row](https://stackoverflow.com/questions/29919306/find-the-column-name-which-has-the-maximum-value-for-each-row) – jpp Feb 09 '18 at 15:59

2 Answers2

2

You can use df.idxmax():

df.idxmax(axis=1)
TYZ
  • 8,466
  • 5
  • 29
  • 60
0

Fun way

df.eq(df.max(1),0).dot(df.columns)
Out[105]: 
0    b
1    d
2    c
dtype: object
BENY
  • 317,841
  • 20
  • 164
  • 234