Python Task. Define a function to analyze car dataset using pandas Define a func
ID: 3750696 • Letter: P
Question
Python Task.
Define a function to analyze car dataset using pandas
Define a function named "analyze_cars" to do the follows:
Take a csv file path string as an input. Assume the csv file is in the format of the provided sample file.
Read the csv file as a dataframe with the first row as column names
Find cars with top 3 mpg among those of origin = 1. Print the names (i.e. "car" column) and mpg of these three cars.
Create a new column called "brand" to store the brand name as the first word in "car" column (hint: use "apply" function)
Show the mean, min, and max mpg values for each of these brands: "ford", "buick" and "honda"
Create a cross tab to show the average mpg of each brand and each origin value. Use "brand" as row index and "origin" as column index.
This function does not have any return. Just print out the result of each calculation step.
(Note use your own csv with sample data)
Sample data for cars.csv
mpg,cylinders,displacement,horsepower,weight,acceleration,model,origin,car
18,8,307,130,3504,12,70,1,chevrolet chevelle malibu
15,8,350,165,3693,11.5,70,1,buick skylark 320
18,8,318,150,3436,11,70,1,plymouth satellite
16,8,304,150,3433,12,70,1,amc rebel sst
17,8,302,140,3449,10.5,70,1,ford torino
15,8,429,198,4341,10,70,1,ford galaxie 500
14,8,454,220,4354,9,70,1,chevrolet impala
14,8,440,215,4312,8.5,70,1,plymouth fury iii
14,8,455,225,4425,10,70,1,pontiac catalina
Explanation / Answer
#~~~~~~~~~~~~~~end of function ~~~~~~~~~~~~~~~~~~~~~~#
# output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.