In this short PA, you will be writing a program that reads in a CSV file with no column labels, and can compute a maximum, minimum of a column.
Also, for extra credit, you can implement an column-average calculation feature.
Name the program csv_processor.py
.
Your program should ask the user for three input values:
Below, and example is show of the program accepting these three values from the user.
Enter CSV file name:
numbers.csv
Enter column number:
1
Enter column operation:
avg
After getting all of this information from the user, your program should do the following:
,
.
You can append the list that split returns to another list.min
, max
, or avg
(avg
for extra credit).
You are only required to calculate an minimum and maximum, though you can add a average calculation for extra credit.You should structure the code into either three or four functions:
main
, to get user inputs and read in the fileLet’s walk through an example.
Let’s say that you requested your program to operate on numbers.csv
, and it had the below contents:
1.5,2.0,3.0
8.0,5.0,7.0
3.0,2.0,2.0
2.0,2.0,2.0
That CSV file has four rows and three columns.
You should store all of the values into a 2D list.
Now, say that the user requested the min
(minimum) calculation on column 2.
The code should loop through the rows of the 2D list, sum up the numeric values, and then calculate the minimum value.
It should print:
The minimum for column 2 is: 2.0
The max of column 2 would be 5.0
and the avg would be 2.75
.
Below are three complete examples.
These examples use a file named numbers.txt
with the same contents shown earlier.
You can also use Gradescope to test your program.
Enter CSV file name:
numbers.csv
Enter column number:
1
Enter column operation:
avg
The average for column 1 is: 3.625
Enter CSV file name:
numbers.csv
Enter column number:
1
Enter column operation:
min
The minimum value in column 1 is: 1.5
You are not required to implement them.
max
, min
, or avg
python functionsSubmit to Gradescope by Sunday, April 12th, by 7pm.
You may not use a late day.
There will be some Gradescope test cases for min
and max
.
There will also be test cases for avg
, for extra credit.