QBoard » Artificial Intelligence & ML » AI and ML - Python » How Solve a Data Science Question Using Python's Panda Data Structure Syntax

How Solve a Data Science Question Using Python's Panda Data Structure Syntax

  • Good afternoon.

    I have this question I am trying to solve using "panda" statistical data structures and related syntax from the Python scripting language. I am already graduated from a US university and employed while currently taking the Coursera.org course of "Python for Data Science" just for professional development, which is offered online at Coursera's platform by the University of Michigan. I'm not sharing answers to anyone either as I abide by Coursera's Honor Code.

    First, I was given this panda dataframe chart concerning Olympic medals won by countries around the world:

    # Summer    Gold    Silver  Bronze  Total   # Winter    Gold.1  Silver.1    Bronze.1    Total.1 # Games Gold.2  Silver.2    Bronze.2    Combined total  ID
    
    Afghanistan 13  0   0   2   2   0   0   0   0   0   13  0   0   2   2   AFG
    Algeria 12  5   2   8   15  3   0   0   0   0   15  5   2   8   15  ALG
    Argentina   23  18  24  28  70  18  0   0   0   0   41  18  24  28  70  ARG
    Armenia 5   1   2   9   12  6   0   0   0   0   11  1   2   9   12  ARM
    Australasia 2   3   4   5   12  0   0   0   0   0   2   3   4   5   12  ANZ

    Second, the question asked is, "Which country has won the most gold medals in summer games?"

    Third, a hint given me as to how to answer using Python's panda syntax is this: "This function should return a single string value."

    Fourth, I tried entering this as the answer in Python's panda syntax:

    import pandas as pd
        df = pd.read_csv('olympics.csv', index_col=0, skiprows=1)
    def answer_one():
        if df.columns[:2]=='00':
            df.rename(columns={col:'Country'+col[4:]}, inplace=True)    
        df_max = df[df[max('Gold')]]
        return df_max['Country']
    answer_one() 

    Fifth, I have tried other various answers like this in Coursera's auto-grader, but it keeps giving this error message:


     

    Could you please help me solve that question? Any hints/suggestions/comments are welcome for that.

    Thanks, Kevin

     
      January 13, 2022 1:46 PM IST
    0
  • import pandas as pd
    def answer_one():
        df1=pd.Series.max(df['Gold'])
        df1=df[df['Gold']==df1]
        return df1.index[0]
    
    answer_one()
      January 29, 2022 2:44 PM IST
    0