Question: Write a academic easy to understand python program that does the following: 1 . Reads the olympics.csv file. Column headers ( Name , Sex, Age,
Write a academic easy to understand python program that does the following:
Reads the olympics.csv file. Column headers Name Sex, Age, Height, NOC, Year, Season, Sport, Medal some of the boxes can have NA if no existing data is present.
Prints the medal count by decade of age.
Prints the average overall age of medal winners of each medal type
You may not use any of the following pandas functions: groupby pivottable readcsv
I would like the python code to be formatted as the example below:
Example:
import pandas as pd
import csv
class Vehicle:
def initself make, model, year, mpgCity, mpgHwy:
self.make make
self.model model
self.year year
self.mpgCity intfloatmpgCitystrip
self.mpgHwy intfloatmpgHwystrip
def strself:
return self.make self.model self.year strselfmpgCity strselfmpgHwy
mpgCity pdSeries
mpgCityAvg pdSeries
mpgHwy pdSeries
mpgHwyAvg pdSeries
with openmpgcsv as infile:
reader csvreaderinfile
reader.next
for rec in reader:
veh Vehiclerec rec rec rec rec
if veh.make in mpgCity:
mpgCityvehmake mpgCityvehmake
mpgCityAvgvehmake mpgCityAvgvehmake veh.mpgCity
mpgHwyvehmake mpgHwyvehmake
mpgHwyAvgvehmake mpgHwyAvgvehmake veh.mpgHwy
else:
mpgCityvehmake
mpgCityAvgvehmake veh.mpgCity
mpgHwyvehmake
mpgHwyAvgvehmake veh.mpgHwy
mpgCityAvg mpgCityAvg mpgCityagstypeint
printmpgCityAvgtostring
print
mpgHwyAvg mpgHwyAvg mpgHwyastypeint
printmpgHwyAvgtostring
df pdDataFramempg city':mpgCityAvg, mpg hwy:mpgHwyAvg
printdf
mpgAvg mpgCityAvg mpgHwyAvgastypeint
printmpgAvg
dfmpg avg' mpgAvg
printdf
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
