Max value using idxmax

前端 未结 8 1445
情歌与酒
情歌与酒 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:23
    def answer_three():
        return ((df[(df['Gold']>0) & (df['Gold.1']>0 )]['Gold'] - df[(df['Gold']>0) & (df['Gold.1']>0 )]['Gold.1'])/df[(df['Gold']>0) & (df['Gold.1']>0 )]['Gold.2']).argmax()
    
    0 讨论(0)
  • 2020-12-22 05:33

    This looks like a question from the programming assignment of courser course - "Introduction to Data Science in Python"

    Having said that if you are not cheating "maybe" the bug is here:

    Gold_Y = df2[(df2['Gold'] > 1) | (df2['Gold.1'] > 1)]
    

    You should use the & operator. The | operator means you have countries that have won Gold in either the Summer or Winter olympics.

    You should not get a NaN in your diff gold.

    0 讨论(0)
提交回复
热议问题