首页 > 解决方案 > 如何比较熊猫数据框中的值

问题描述

说A是一个数据框,表示奥运会比赛中所有国家的数据。

我正在尝试打印所有具有最大值的国家/地区的数据:(summer_gold - winter_gold)/总黄金数。

请检查我的代码,让我在这里做错了什么。

def answer_three():
    count=A['Gold'].count() + A['Gold.1'].count()  #Gold is no. of summer gold & Gold.1 is winter gold
    X=(((A['Gold']-A['Gold.1']).abs())/count).max() 
    Y=A.where(((A['Gold']-A['Gold.1'].abs())/count).max() == X)
    return Y
answer_three()

我得到的错误是:

"Array conditional must be same shape as self"

标签: python-3.xpandasnumpydataframe

解决方案


推荐阅读