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
def answer_three():
     atleast_one_gold = df[(df['Gold']>1) & (df['Gold.1']> 1)]
     return ((atleast_one_gold['Gold'] - atleast_one_gold['Gold.1'])/atleast_one_gold['Gold.2']).idxmax()
answer_three()
                                                                        I an pretty new to python or programming as a whole. So my solution would be the most novice ever! I love to create variables; so you'll see a lot in the solution.
    def answer_three:
      a = df.loc[df['Gold'] > 0,'Gold']
           #Boolean masking that only prints the value of Gold that matches the condition as stated in the question; in this case countries who had at least one Gold medal in the summer seasons olympics.
      b = df.loc[df['Gold.1'] > 0, 'Gold.1']
           #Same comment as above but 'Gold.1' is Gold medals in the winter seasons 
      dif = abs(a-b)
           #returns the abs value of the difference between a and b.
      dif.dropna()
           #drops all 'Nan' values in the column.
      tots = a + b
           #i only realised that this step wasn't essential because the data frame had already summed it up in the column 'Gold.2'
      tots.dropna()
      result = dif.dropna()/tots.dropna()
      returns result.idxmax
           # returns the index value of the max result
                                                                        def answer_two():
    df2=pd.Series.max(df['Gold']-df['Gold.1'])
    df2=df[df['Gold']-df['Gold.1']==df2]
    return df2.index[0]
answer_two()
                                                                        def answer_three():
    _df = df[(df['Gold'] > 0) & (df['Gold.1'] > 0)]
    return ((_df['Gold'] - _df['Gold.1']) / _df['Gold.2']).argmax() answer_three()
                                                                        def answer_three():
    diff=df['Gold']-df['Gold.1']
    relativegold = diff.abs()/df['Gold.2']
    df['relativegold']=relativegold
    x = df[(df['Gold.1']>0) &(df['Gold']>0) ]
    return x['relativegold'].idxmax(axis=0)
answer_three()
                                                                        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()