pandas 行中的最大值并返回 df 以及值和列名称

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)

Cod*_*ent 5

尝试这个:

result = df.max(axis=1)
result.index = df.idxmax(axis=1)
Run Code Online (Sandbox Code Playgroud)


ank*_*_91 5

使用np.argmaxdf.lookup

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)