a12*_*234 3 python python-3.x pandas
我有以下数据框:
a b c d e
1 .90 .95 .83 .56
.95 .96 .87 .83 .63
.83 .87 .83 .95 .81
Run Code Online (Sandbox Code Playgroud)
如何找到每行及其来自的列的最大值,使其看起来像:
a 1
b .96
d .95
Run Code Online (Sandbox Code Playgroud)
尝试这个:
result = df.max(axis=1)
result.index = df.idxmax(axis=1)
Run Code Online (Sandbox Code Playgroud)
s=pd.Series(df.columns[np.argmax(df.values,axis=1)])
final=pd.DataFrame(df.lookup(s.index,s),s)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3205 次 |
| 最近记录: |