Question: Input Output Exercise: (Please answer the exercise in PYTHON code) Part 1 The tollowing code loads the olympics dataset (olympics.csv), which was derrived from the
Part 1 The tollowing code loads the olympics dataset (olympics.csv), which was derrived from the Wikpedia entry on All Time olympkc Games Medals, and does some basic 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 to answer the questions below : import pandas as pd df pd.read_csv('olympics.csv', index col-e, 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: oruns-(col: Bronze'icol[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 df[.ID, ] . names-ids . str[1].str[:3] # the [1] is the country name (new index) element is the abbreviation or ID (take first 3 characters from that) df df.drop( Totals) df.head(O
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
