Max value using idxmax

前端 未结 8 1498
情歌与酒
情歌与酒 2020-12-22 04:55

I am trying to calculate the biggest difference between summer gold medal counts and winter gold medal counts relative to their total gold medal count. The problem is that

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-22 05:22

    Try this code after subbing in the correct (your) function and variable names. I'm new to Python, but I think the issue was that you had to use the same variable in Line 4 (df1['difference']), and just add the method (.idxmax()) to the end. I don't think you need the first line of code for the function, either, as you don't use the local variable (Gold_Y). FYI - I don't think we're working with the same dataset.

    def answer_three():
        df1['difference'] = (df1['Gold']-df1['Gold.1']).abs()/df1['Gold.2']
        return df1['difference'].idxmax()
    
    answer_three()
    

提交回复
热议问题