Python 获取数据帧的最大值

Python 获取数据帧的最大值,python,pandas,data-science,Python,Pandas,Data Science,我有一个数据框架,其中包含国家名称和列的索引。 我想知道金牌最多的国家的名字。 我试过这个: def answer_one(): x= df[df['Gold.2']==df['Gold.2'].max()] return x.index answer_one() 我只想得到一个字符串,这个字符串是国家的名称,但是我一直在得到这个字符串 Index(['United States'], dtype='object') 由于您需要具体的值,我将使用以下代码: def answe

我有一个数据框架,其中包含国家名称和列的索引。 我想知道金牌最多的国家的名字。 我试过这个:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index
answer_one()
我只想得到一个字符串,这个字符串是国家的名称,但是我一直在得到这个字符串

Index(['United States'], dtype='object')

由于您需要具体的值,我将使用以下代码:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values[0]
answer_one()
这将返回第一个max国家/地区。如果需要包含所有max国家/地区的数组:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values
answer_one()

由于您需要具体的值,我将使用以下代码:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values[0]
answer_one()
这将返回第一个max国家/地区。如果需要包含所有max国家/地区的数组:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values
answer_one()