|
| 1 | +from pandas import DataFrame, Series |
| 2 | + |
| 3 | +################# |
| 4 | +# Syntax Reminder: |
| 5 | +# |
| 6 | +# The following code would create a two-column pandas DataFrame |
| 7 | +# named df with columns labeled 'name' and 'age': |
| 8 | +# |
| 9 | +# people = ['Sarah', 'Mike', 'Chrisna'] |
| 10 | +# ages = [28, 32, 25] |
| 11 | +# df = DataFrame({'name' : Series(people), |
| 12 | +# 'age' : Series(ages)}) |
| 13 | + |
| 14 | +def create_dataframe(): |
| 15 | + ''' |
| 16 | + Create a pandas dataframe called 'olympic_medal_counts_df' containing |
| 17 | + the data from the table of 2014 Sochi winter olympics medal counts. |
| 18 | +
|
| 19 | + The columns for this dataframe should be called |
| 20 | + 'country_name', 'gold', 'silver', and 'bronze'. |
| 21 | +
|
| 22 | + There is no need to specify row indexes for this dataframe |
| 23 | + (in this case, the rows will automatically be assigned numbered indexes). |
| 24 | + |
| 25 | + You do not need to call the function in your code when running it in the |
| 26 | + browser - the grader will do that automatically when you submit or test it. |
| 27 | + ''' |
| 28 | + |
| 29 | + countries = ['Russian Fed.', 'Norway', 'Canada', 'United States', |
| 30 | + 'Netherlands', 'Germany', 'Switzerland', 'Belarus', |
| 31 | + 'Austria', 'France', 'Poland', 'China', 'Korea', |
| 32 | + 'Sweden', 'Czech Republic', 'Slovenia', 'Japan', |
| 33 | + 'Finland', 'Great Britain', 'Ukraine', 'Slovakia', |
| 34 | + 'Italy', 'Latvia', 'Australia', 'Croatia', 'Kazakhstan'] |
| 35 | + |
| 36 | + gold = [13, 11, 10, 9, 8, 8, 6, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] |
| 37 | + silver = [11, 5, 10, 7, 7, 6, 3, 0, 8, 4, 1, 4, 3, 7, 4, 2, 4, 3, 1, 0, 0, 2, 2, 2, 1, 0] |
| 38 | + bronze = [9, 10, 5, 12, 9, 5, 2, 1, 5, 7, 1, 2, 2, 6, 2, 4, 3, 1, 2, 1, 0, 6, 2, 1, 0, 1] |
| 39 | + |
| 40 | + # your code here |
| 41 | + |
| 42 | + ## My code starts here |
| 43 | + data = {'country_name':Series(countries), |
| 44 | + 'gold':Series(gold), 'silver':Series(silver), 'bronze':Series(bronze)} |
| 45 | + olympic_medal_counts_df = DataFrame(data) |
| 46 | + #My code ends here |
| 47 | + |
| 48 | + return olympic_medal_counts_df |
| 49 | + |
| 50 | +print(create_dataframe()) |
0 commit comments