jeudi 9 février 2017

Olympic Medals Points system, 3 for Gold, 2 for Silver, 1 for Bronze

Vote count: 0

Write a function that creates a Series called "Points" which is a weighted value where each gold medal (Gold.2) counts for 3 points, silver medals (Silver.2) for 2 points, and bronze medals (Bronze.2) for 1 point. The function should return only the column (a Series object) which you created.

This function should return a Series named Points of length 146

I'm new to python and pandas and I don't know if I'm on the right track or not with this code but I'm getting a key error

KeyError: "['Gold.2' 'Silver.2' 'Bronze.2'] not in index" for this code: 

import pandas as pd

df = pd.read_csv('olympics.csv', index_col=0, skiprows=1)

def answer_four():

    df['Points'] = df[(df[['Gold.2','Silver.2','Bronze.2']], [3,2,1])]
    #df[['Gold.2','Silver.2','Bronze.2']].apply(lambda x:(x,[3,2,1]))
    olympic_points_df = df[['Points']]


    return olympic_points_df

answer_four()

Any help with this would be much appreciated.

asked 13 secs ago

Let's block ads! (Why?)



Olympic Medals Points system, 3 for Gold, 2 for Silver, 1 for Bronze

Aucun commentaire:

Enregistrer un commentaire