Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

INPUT FILE: Outcomes Loops and Conditions Dictionaries Functions Question 1: Required For this question, you will revised what was asked of you in assignment 1.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

INPUT FILE:

image text in transcribed

Outcomes Loops and Conditions Dictionaries Functions Question 1: Required For this question, you will revised what was asked of you in assignment 1. You will re-implement your solution using nested dictionaries instead to store the results of your statistics calculations you will decompose your program using functions. Your program should not need to make use of concepts and constructs beyond functions as covered in class. As in assignment 1, you will develop a program to calculate some statistics for a csv file. As an example, the csv file reducedweather.csv contains tabular data which includes Manitoba daily minimum and maximum temperatures (2 columns) from Jan until Sept 17 in 2019. The first row is a header record (row), with headings Max Temp and Min Temp. This is known as the header record. After the header row, each row is a day where maximum and minimum temperature for that day is recorded. From this file, you need to calculate mean, standard deviation, highest and lowest temperature for each column. You may assume that each csv file that your program reads will have a header record with a fixed number of columns, say c columns, and the remaining rows each consists of c columns of numerical data values (also known as observations) The description for this problem is the same as the assignment 1 question 1. But in this assignment you need to create functions for reading the file, finding standard deviation, squared difference, max and mean value, and printing the results. Step 1 - Creating a module of functions for computing statistics As a first step, create a module with name Statistics Calculation. To create the module, you can open a new python script. Save the script with the given name StatisticsCalculation.py. The statistics calculation module contains following functions. Your functions should do the computations directly without relying on any Python functions such as min, nax, sun etc, calculateMean(data): The parameter data is a list of floating point values. This function will calculate and return the mean. Remember, data is a single list, it does not contain any nested list. calculateStdDev(data) calculateStd Dev(data): Given a list of data values, calculate and return the standard deviation. Again remember, data is a single list, it does not contain any nested list. findMin(data): Given a list of data, this function will return the min. The parameter data is a single list, it does not contain any nested list. You can not use any built in function to calculate the minimum value. In this function, you need to implement your own function to find the minimum element in data. findMax(data): Given a list of data, this function will return the max. The parameter data is a single list, it does not contain any nested list. You can not use any built in function to calculate the maximum value. In this function, you need to implement your own function to find the maximum element in date. Step 2 - Creating a module for Input/Output and the main function In this step, you will create another module with name InputOutputHandler. To create the module, you can open a new python script. Save the script with the given name InputOutputHandler.py. This module contains the following functions: printCSVResults(columns Dictionary): This function will display a table of results (see sample output bellow). This functions has a single parameter columns Dictionary which is a nested dictionary keyed by the column name. For oach column name, the value stored in the dictionary is another dictionary holding the values for the minimum, maximum and standard deviation for that column. To get the keys ordered in a consistent manner for printing, you may want to use the sorted. Sample code is given below on usage. 2.0) d['Bob'] = "2044748845 d['Amy'] . 2048749484" d[ 'Albert') "2044349423" d['Janes') "2042685555" d['Albert'] - "2044349423" d['Janes'] = "204268SSSS* for i in sorted (d.keys(): # get keys in ascending order print(i, end = "") readCSVFile(fileName): This function will read in the CSV file. The parameter filettane is a string. Open the file and read the header row and data from the csv file. This function will return the header and data. It is important that the function be able to read any number of columns from the csv file. main(): Create a main function and from the main function call these appropriate functions to read in a CSV file (as inputted by the user), compute the required statistics for each column, and display the results. In your main function, you should use a nested dictionary for storing the minimums, maximums, standard deviations of each column that you have computed (instead of a bunch of lists used in Assignment 1). Your main dictionary should be keyed by the column name and the value stored in the dictionary for that key is another dictionary that contains the minimum maximum, and standard deviation for that column. Step 3-Creating the FirstnameLastname A101.py File In this file, import the StatisticsCalculation module and call the main function. This is the program that should be executed by Python (with will in turn make use of the other modules). Testing You should test your program on various CSV files including reducedweather.csv and Bodyfat.csv from assignment 1. Data source: http://climate.weather.gc.ca/climate data/daily_data_e.html?StationID=27174 Sample output: Testing You should test your program on various CSV files including reducedweather.csv and Bodyfat.csv from assignment 1. Data source: http://climate.weather.gc.ca/climate_data/daily_data_e.html?StationID=27174 Sample output: Enter file name: reducedweather.csv Column Names Mean Std Deviation Highest Score Lowest Score Max Templ 10.101 16.91 36.60 - 29.80 Min Temp -2.20 21.301 - 39.96 Programmed by the Instructors Date: Tue Feb 4 11:48:07 2020 End of processing What to hand in Hand in the three python files StatisticsCalculation.py, InputOutputHandler.py and FirstnameLastnameA101.py. G H A IB 1 Max Tem, Min Temp -18.3 -28.3 -4.5 -18.5 3.8 -6.3 1.5 -9.6 -2.1 -9.5 -2.7 -12.3 0.6 -8.4 -8.3 -16.5 -15.5 -19.3 -9 -15.7 -9.1 -13.7 -5.6 -13.8 -5.1 -6.4 -11.4 -3.7 -23.5 -18.8 -27.8 -17.9 -27.4 -25.7 -30.2 -25 -31.9 -22.2 -33.2 -11.5 -23.2 -19.4 -14 2 -7 Outcomes Loops and Conditions Dictionaries Functions Question 1: Required For this question, you will revised what was asked of you in assignment 1. You will re-implement your solution using nested dictionaries instead to store the results of your statistics calculations you will decompose your program using functions. Your program should not need to make use of concepts and constructs beyond functions as covered in class. As in assignment 1, you will develop a program to calculate some statistics for a csv file. As an example, the csv file reducedweather.csv contains tabular data which includes Manitoba daily minimum and maximum temperatures (2 columns) from Jan until Sept 17 in 2019. The first row is a header record (row), with headings Max Temp and Min Temp. This is known as the header record. After the header row, each row is a day where maximum and minimum temperature for that day is recorded. From this file, you need to calculate mean, standard deviation, highest and lowest temperature for each column. You may assume that each csv file that your program reads will have a header record with a fixed number of columns, say c columns, and the remaining rows each consists of c columns of numerical data values (also known as observations) The description for this problem is the same as the assignment 1 question 1. But in this assignment you need to create functions for reading the file, finding standard deviation, squared difference, max and mean value, and printing the results. Step 1 - Creating a module of functions for computing statistics As a first step, create a module with name Statistics Calculation. To create the module, you can open a new python script. Save the script with the given name StatisticsCalculation.py. The statistics calculation module contains following functions. Your functions should do the computations directly without relying on any Python functions such as min, nax, sun etc, calculateMean(data): The parameter data is a list of floating point values. This function will calculate and return the mean. Remember, data is a single list, it does not contain any nested list. calculateStdDev(data) calculateStd Dev(data): Given a list of data values, calculate and return the standard deviation. Again remember, data is a single list, it does not contain any nested list. findMin(data): Given a list of data, this function will return the min. The parameter data is a single list, it does not contain any nested list. You can not use any built in function to calculate the minimum value. In this function, you need to implement your own function to find the minimum element in data. findMax(data): Given a list of data, this function will return the max. The parameter data is a single list, it does not contain any nested list. You can not use any built in function to calculate the maximum value. In this function, you need to implement your own function to find the maximum element in date. Step 2 - Creating a module for Input/Output and the main function In this step, you will create another module with name InputOutputHandler. To create the module, you can open a new python script. Save the script with the given name InputOutputHandler.py. This module contains the following functions: printCSVResults(columns Dictionary): This function will display a table of results (see sample output bellow). This functions has a single parameter columns Dictionary which is a nested dictionary keyed by the column name. For oach column name, the value stored in the dictionary is another dictionary holding the values for the minimum, maximum and standard deviation for that column. To get the keys ordered in a consistent manner for printing, you may want to use the sorted. Sample code is given below on usage. 2.0) d['Bob'] = "2044748845 d['Amy'] . 2048749484" d[ 'Albert') "2044349423" d['Janes') "2042685555" d['Albert'] - "2044349423" d['Janes'] = "204268SSSS* for i in sorted (d.keys(): # get keys in ascending order print(i, end = "") readCSVFile(fileName): This function will read in the CSV file. The parameter filettane is a string. Open the file and read the header row and data from the csv file. This function will return the header and data. It is important that the function be able to read any number of columns from the csv file. main(): Create a main function and from the main function call these appropriate functions to read in a CSV file (as inputted by the user), compute the required statistics for each column, and display the results. In your main function, you should use a nested dictionary for storing the minimums, maximums, standard deviations of each column that you have computed (instead of a bunch of lists used in Assignment 1). Your main dictionary should be keyed by the column name and the value stored in the dictionary for that key is another dictionary that contains the minimum maximum, and standard deviation for that column. Step 3-Creating the FirstnameLastname A101.py File In this file, import the StatisticsCalculation module and call the main function. This is the program that should be executed by Python (with will in turn make use of the other modules). Testing You should test your program on various CSV files including reducedweather.csv and Bodyfat.csv from assignment 1. Data source: http://climate.weather.gc.ca/climate data/daily_data_e.html?StationID=27174 Sample output: Testing You should test your program on various CSV files including reducedweather.csv and Bodyfat.csv from assignment 1. Data source: http://climate.weather.gc.ca/climate_data/daily_data_e.html?StationID=27174 Sample output: Enter file name: reducedweather.csv Column Names Mean Std Deviation Highest Score Lowest Score Max Templ 10.101 16.91 36.60 - 29.80 Min Temp -2.20 21.301 - 39.96 Programmed by the Instructors Date: Tue Feb 4 11:48:07 2020 End of processing What to hand in Hand in the three python files StatisticsCalculation.py, InputOutputHandler.py and FirstnameLastnameA101.py. G H A IB 1 Max Tem, Min Temp -18.3 -28.3 -4.5 -18.5 3.8 -6.3 1.5 -9.6 -2.1 -9.5 -2.7 -12.3 0.6 -8.4 -8.3 -16.5 -15.5 -19.3 -9 -15.7 -9.1 -13.7 -5.6 -13.8 -5.1 -6.4 -11.4 -3.7 -23.5 -18.8 -27.8 -17.9 -27.4 -25.7 -30.2 -25 -31.9 -22.2 -33.2 -11.5 -23.2 -19.4 -14 2 -7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions