![](/img/trans.png)
[英]How to get max value AND respective column name with pandas dataframe
[英]From a DataFrame how do I get the column name for the column that has the max value
如果我有一個包含數值的 DataFrame,我如何確定哪一列包含最大值?
EEM_X | EFA_X | QQQ_X | 間諜_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 |
我想添加一個新列 ['MAX'] ,其中包含每行中的值最高的列名。
這應該工作:
df.apply(pd.Series.idxmax, axis=1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.