$25
For the final project, you are to create an interactive CSV analysis program in Python named csval.py according to the requirements specified in this document.
Description:
Create a menu-driven program that reads in a CSV file and identifies the maximum value of a user selected attribute and the corresponding object that the maximum value belongs to. This Wikipedia article describes a CSV file:
https://en.wikipedia.org/wiki/Comma-separated_values During a session, the program is to prompt the user for the name of the CSV file and present a menu of the available attributes derived from the CSV file. The user will then make a selection from the attribute menu and the program will present the maximum value for the object and
the name of the object.
CSV File Format:
While all CSV files do not fit this particular format, you are guaranteed that all CSV files entered by the user will match the following format. Multiple CSV files are provided for testing. They are contained in a file attached to the assignment called CSVTestFiles.zip. To examine how the data looks within the CSV file and how Python will read each line, the file can be opened with any text editor. The file can also be opened within Excel to show a tabular version of the data; note that how the data appears in Excel will not be how it appears in Python till after you create a
two-dimensional list of the data.
The following is a small sample CSV file (displayed as if it was opened with a text editor):
Student,Midterm,Final Project,Final Exam
Kelly,95,92,93
Joe,84,94,92
If the sample CSV file was parsed and turned into a two-dimensional list, it would appear as the following:
All values within the CSV file are separated by commas. Row 0 of the CSV file contains the attributes from Column 1 to the final column of the CSV file (in this example, that would-be column 3). Within the above sample, there would be three separate attributes (“Midterm”, Column 0 Column 1 Column 2 Column 3
Row 0 Student Midterm Final Project Final Exam
Row 1 Kelly 95 92 93
Row 2 Joe 84 94 92
CSV Analytics
Final Project
“Final Project”, “Final Exam”) that the user should be able to select from the menu in the program. You can think of row 0 as the column headers for the rest of the data.
The rest of the rows within the CSV file, contains the objects that will be examined to identify the max value. In this example, there would be two objects (“Kelly” and “Joe”). Kelly has a grade of 95% for the midterm, 92% for the final project, and a 93% for the final exam. Joe, on the other hand, has a grade of 84% for the midterm, 94% for the final project, and a 92% for the final exam.
The element in row 0, column 0 is to always be ignored since this element is the column header for the object names. In this example, “Student” would be the element to be ignored.
The following would be the menu derived from this sample CSV file:
1. Midterm
2. Final Project
3. Final Exam
If a user selected the “Midterm” attribute within our program, the program would print off:
Largest Midterm value is Kelly with 95.0
All elements in the CSV file that is not an object name or an attribute is a number. Each number value within the CSV file can be represented with a floating-point number. Do not use Integers since some of the values may have decimal precision or scientific notation (e.g. 1.0E+11).
Converting a string to a floating-point number handles these inconsistencies for you.
Requirements:
The program is to prompt the user for the name of the CSV file. If an exception occurs trying to open or read the file, an error message is to be displayed. The program is not to crash if the file is not found or there is an error reading the file. Use try- except!
Read the CSV file and create a two-dimensional list with the contents of the file. Each line of the
file should be split upon the comma (e.g. “,”).
Display a menu from the available attributes from the CSV file and prompt the user to make a selection from the menu by entering the number of their choice. If the user enters something other than a number or a number in the range of the choices provided in the menu they are to be given feedback that their choice is not valid and asked for the input again. Under no circumstance should input from the user crash the program.
The output from the program is to display the selected attribute, the maximum value from that attribute and the object’s name that the maximum value belongs to.
After the output is displayed to the user, the program should ask the user if they would like to analyze another attribute. Use the prompt: Would you like to conduct another analysis on an attribute? (y/n) If the user answers y, then the program is to present the attribute menu again and accept input for another attribute. If the user answers with anything other than y, the program is to ask the user if they would like to evaluate another CSV file. Use the prompt: Would you like to evaluate another file? (y/n) If the user answers y, then the program is to accept input for another file name. If the user answers with anything other than y, the program is to exit.
The number of attributes displayed in the menu should NOT be hardcoded but be derived from the CSV file. If the CSV file has 2 attributes, the attribute menu should show 2 attributes to choose from; but if the CSV file has 15 attributes, the attribute menu should show 15 attributes to choose from.
Sample Output:
All CSV files are attached to this assignment.
(user input is highlighted in orange)
Sample output 1:
Welcome to CSV Analytics!
Enter the name of the file you would like to process: grades.csv
Attributes:
1. Midterm
2. Final Project
3. Final Exam
4. Participation
Enter choice: 1
Largest Midterm value is Kelly with 95.0
Would you like to conduct another analysis on an attribute? (y/n) y
Attributes:
1. Midterm
2. Final Project
3. Final Exam
4. Participation
Enter choice: 2
Largest Final Project value is Joe with 94.0
Would you like to conduct another analysis on an attribute? (y/n) n
Would you like to evaluate another file? (y/n) n
CSV Analytics
Final Project
Sample output 2:
Welcome to CSV Analytics!
Enter the name of the file you would like to process: miniCountries.csv
Attributes:
1. Area
2. GDP
3. Population
Enter choice: 1
Largest Area value is United States with 9631418.0
Would you like to conduct another analysis on an attribute? (y/n) n
Would you like to evaluate another file? (y/n) y
Enter the name of the file you would like to process: grades.csv
Attributes:
1. Midterm
2. Final Project
3. Final Exam
4. Participation
Enter choice: 3
Largest Final Exam value is Kelly with 93.0
Would you like to conduct another analysis on an attribute? (y/n) n
Would you like to evaluate another file? (y/n) n
References:
Review chapter 6 of the textbook to review how to read from a file. A CSV file can be read
exactly the same as a TXT file.
Review chapter 8.3 of the textbook to review how to manipulate and split strings based on a
character.
Review chapter 7.8 of the textbook to review two-dimensional lists.
Review the Two-Dimensional Lists and Advanced List Operations.pdf file to review twodimensional
lists and how to work with them.
CSV Analytics
Final Project
Testing:
Once you have written your program you need to test it thoroughly. Three sample CSV files
matching the discussed format are provided for testing (grades.csv, miniCountries.csv,
countries.csv). These files are contained in a file attached to the assignment called
CSVTestFiles.zip. You must unzip the file to get the folder containing the files. You can also hand
create files that match the discussed format.
CSV Analytics Final Project