If I have a DataFrame with numeric values in it, how do I determine which column contains the max value?
EEM_X | EFA_X | QQQ_X | SPY_X | |
---|---|---|---|---|
126 | 0.1898 | 0.1490 | 0.1025 | 0.0965 |
127 | 0.1911 | 0.1476 | 0.0678 | 0.0793 |
128 | 0.1986 | 0.1590 | 0.0750 | 0.0893 |
129 | 0.2180 | 0.1703 | 0.0783 | 0.0924 |
I want to add a new column ['MAX'] that contains the column name where the value in each row is the highest.
This shoud work:
df.apply(pd.Series.idxmax, axis=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.