any help on this please

Get perfect grades by consistently using our writing services. Place your order and get a quality paper today. Take advantage of our current 20% discount by using the coupon code GET20


Order a Similar Paper Order a Different Paper

Overview

In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc.

Provided Input Files

An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same as what you had for your chapter 13 labs). The following is an example of some of the lines in the file:

mpg,cylinders,displacement,horsepower,weight,acceleration,model_year,origin,name_x000D_
18,8,307,130,3504,12,70,usa,chevrolet chevelle malibu_x000D_
15,8,350,165,3693,11.5,70,usa,buick skylark 320_x000D_
18,8,318,150,3436,11,70,usa,plymouth satellite_x000D_
16,8,304,150,3433,12,70,usa,amc rebel sst_x000D_

Description

The first thing your program will need to do is prompt the user for a csv file name. Your prompt must be exactly Enter the filename:You will then read that csv file into a dataframe, and use that data in your analysis. If the file can not be opened, your program should not crash, but should print out the message Can't open file. Exiting program. and then exit the program.

You will use a menu, like in the last project, and call several functions according to the user’s menu selection.

You program should have a menu exactly as follows (the menu always prints a blank line first):

(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:_x000D_

If the user enters an invalid menu selection (including a non-numeric input, or a number outside of the valid range), your program should not crash, but should print the message Invalid selection - must be a number from 1 to 4, then display the menu again. For each menu selection other than Exit, you will first prompt the user for a country of origin. The prompt should be exactly Enter the country of origin: (with a space following the colon). The countries that are in the file are “usa”, “japan”, and “europe”. Then you will call a function for each menu selection and country that was input. If the user enters an unexpected input for the country, you should output the message Invalid country and then display the entire menu again, including the beginning blank line (you do not need to remember which menu item they selected).

An example of what output should look like for a sample of various inputs follows this description.

You will need to use the following functions:

  • def get_max_mpg_model(carsdataframe, country) – this function will accept as parameters a dataframe of data, with the same columns as the original file, and a country, which is a string. The function should return a string which is the name of the car model from the country indicated that has the maximum mpg of all models from that country. For example, if the user selected menu item 1 and then input ‘usa’, the get_max_mpg_model function will be passed a data frame and the string ‘usa’. It will return the string ‘chevrolet chevette’, since the chevrolet chevette is the model name with the best mpg among those models in the data whose country of origin is the usa. Upon return from the function with the above parameters, the following message should be printed: Best mpg model from usa is chevrolet chevette
  • def get_min_mpg_model(carsdataframe, country) – this function is the same as the get_max_mpg_model function, but will return the model name with the minimum mpg for the indicated country. The message printed upon return from the function would be something like Worst mpg model from usa is chevrolet chevette
  • def get_model_year_range(carsdataframe, country) – this function will take as parameters a dataframe and a country, like the other two, but this function will return two values, the minimum model year and the maximum model year for the indicated country. The message printed upon return from this function is, as an example Model years range from 1970 to 1975. Note that when the data is read into the data frame, the years are two digit integers. You will have to change them to strings in order to output the correct message.
  • Your code will be cleaner and much easier if you create a function that prints the menu.

In the main program, you should open the input file using the pandas read_csv() method and read the contents of the file into a DataFrame. Then display the menu to see what the user wants to do, and perform the function as indicated by the user.

Once the selected menu function has returned, the main program should print out the best (max) mpg model, the worst (min) mpg model, or the model year range according to the selected function, as follows:

Example: If the user inputs the following, in order:

mpg.csv_x000D_
1_x000D_
usa_x000D_
3_x000D_
japan_x000D_
2_x000D_
europe_x000D_
4_x000D_

the console will look like this:

Enter the filename:mpg.csv_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:1_x000D_
_x000D_
Enter the country of origin: usa_x000D_
Best mpg model from usa is: chevrolet chevette_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:3_x000D_
_x000D_
Enter the country of origin: japan_x000D_
Model years range from 1970 to 1975_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:2_x000D_
_x000D_
Enter the country of origin: europe_x000D_
Worst mpg model from europe is: volvo 145e (sw)_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:4_x000D_

If the user inputs a bogus file name, the output should look like this:

Enter the filename:bogusfilename_x000D_
Can't open file.  Exiting program._x000D_

If the user inputs an invalid menu choice, like -3 or end, the output should look like this:

Enter the filename:mpg.csv_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:-3_x000D_
Invalid selection - must be a number from 1 to 4_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:end_x000D_
Invalid selection - must be a number from 1 to 4_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:4_x000D_

If the user inputs an invalid country, such as australia, the output should look like this:

Enter the filename:mpg.csv_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:1_x000D_
_x000D_
Enter the country of origin: australia_x000D_
Invalid country_x000D_
_x000D_
(1) Get max mpg model_x000D_
(2) Get min mpg model_x000D_
(3) Get model year range_x000D_
(4) Exit_x000D_
_x000D_
Enter selection 1-4:4_x000D_

"Is this question part of your assignment? We can help"

ORDER NOW

Got stuck with another paper? We can help! Use our paper writing service to score better grades and meet your deadlines.

Get 15% discount for your first order


Order a Similar Paper Order a Different Paper
Writerbay.net