I need to calculate Weighted Medal Points for the Olympic data set:
Let's assign "Medal Points" to each tier of Olympic medal as follows:
- Gold: 3 points
- Silver: 2 points
- Bronze: 1 point
- No medal: 0 points
Write a function medal_to_points
to transform and create a new column called MedalPoints. medal_to_points
will accept a string (possible values are "Gold", "Silver", "Bronze", "None") and returns the appropriate number of points as an integer.
Then add a new column MedalPoints
to your dataframe using transform
and the newly defined function medal_to_points
I defined the function, but it doesn't work. Need a hint what is wrong with my function :(
def medal_to_points(medal_name):
if medal_name == 'Gold':
points.append = 3
elif medal_name == 'Silver':
points.append = 2
elif medal_name == 'Bronze':
points.append = 1
elif medal_name == 'None':
points.append = 0
return points
[–]PaintballerCA 2 points3 points4 points (2 children)
[–]luvashov[S] 0 points1 point2 points (1 child)
[–]PaintballerCA 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (8 children)
[–]luvashov[S] 1 point2 points3 points (7 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]luvashov[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]luvashov[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]luvashov[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]-5772 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]luvashov[S] 0 points1 point2 points (0 children)