我有一個數據框,看起來像這樣。獲取數據框中最大值的(行,列)指數
import pandas as pd
data = [[5, 7, 10], [7, 20, 4,], [8, 1, 6,]]
cities = ['Boston', 'Phoenix', 'New York']
df = pd.DataFrame(data, columns=cities, index=cities)
輸出:
Boston Phoenix New York
Boston 5 7 10
Phoenix 7 20 4
New York 8 1 6
而且我希望能夠找到城市對具有最大的價值。在這種情況下,我想要返回鳳凰城,鳳凰城。
我曾嘗試:
cityMax = df.values.max()
cityPairs = df.idxmax()
第一個只給了我最大的值(20)和第二給我每個城市最多對不只是整體的最大。有沒有辦法爲數據框中的指定值返回索引和列標題?
相關:[返回索引/索引的列表,其中在熊貓數據框中出現最小/最大值](https://stackoverflow.com/questions/36333402/return-list-of-indices-index-其中-A-最小 - 最大 - 值發生-IN-A-大熊貓非數據幀) – smci