Course Hero Logo

Assignment+2.py - # coding: utf-8 # -# # _You are currently...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 2 out of 4 pages.

# coding: utf-8# ---## _You are currently looking at **version 1.1** of this notebook. To downloadnotebooks and datafiles, as well as get help on Jupyter notebooks in the Courseraplatform, visit the [Jupyter Notebook FAQ](-data-analysis/resources/0dhYG) course resource._## ---# # Assignment 2 - Pandas Introduction# All questions are weighted the same in this assignment.# ## Part 1# The following code loads the olympics dataset (olympics.csv), which was derrivedfrom the Wikipedia entry on [All Time Olympic Games Medals](), and does somebasic data cleaning.## The columns are organized as # of Summer games, Summer medals, # of Winter games,Winter medals, total # number of games, total # of medals. Use this dataset toanswer the questions below.# In[ ]:import pandas as pddf = pd.read_csv('olympics.csv', index_col=0, skiprows=1)for col in df.columns:if col[:2]=='01':df.rename(columns={col:'Gold'+col[4:]}, inplace=True)if col[:2]=='02':df.rename(columns={col:'Silver'+col[4:]}, inplace=True)if col[:2]=='03':df.rename(columns={col:'Bronze'+col[4:]}, inplace=True)if col[:1]=='№':df.rename(columns={col:'#'+col[1:]}, inplace=True)names_ids = df.index.str.split('\s\(') # split the index by '('df.index = names_ids.str[0] # the [0] element is the country name (new index)df['ID'] = names_ids.str[1].str[:3] # the [1] element is the abbreviation or ID(take first 3 characters from that)df = df.drop('Totals')df.head()# ### Question 0 (Example)## What is the first country in df?#

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
professor_unknown
Tags
Gold medal

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture