【发布时间】:2015-06-12 20:06:32
【问题描述】:
我有一个看起来像这样的数据框。
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
并且我希望能够找到具有最大价值的城市对。在这种情况下,我想返回 Phoenix,Phoenix。
我试过了:
cityMax = df.values.max()
cityPairs = df.idxmax()
第一个只给我最大值(20),第二个给我每个城市的最大值对,而不仅仅是整体最大值。有没有办法返回数据框中指定值的索引和列标题?
【问题讨论】:
标签: python numpy indexing max dataframe