0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

pandas DataFrameで最大最小値の行名,列名を取得(argmax/argmin)

Last updated at Posted at 2021-12-12

こんな感じでとれます

import pandas as pd
import numpy as np

def argmaxdf(table):
    argmax=lambda A: np.unravel_index(np.array(A).argmax(), np.array(A).shape)
    row, col = argmax(table.values)
    row, col = table.index[row], table.columns[col]
    return row, col

table = pd.DataFrame(pd.DataFrame(np.random.rand(5,8),
                                  index=list("abcde"),
                                  columns=list("fghijklm")))

display(table,
        argmaxdf(table)
       )

Screen Shot 2021-12-12 at 16.27.59.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?