Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a PYTHON program to read daily precipitation from a file and create a new

ID: 675382 • Letter: W

Question

Write a PYTHON program to read daily precipitation from a file and create a new file that has the monthly totals. There are 10 years of data in the precipitation file, with data for each day of the month. Some days there were errors in recording the data and NA has been entered. You should use functions wisely to make your code more modular and testable.

The input file is attached in the mail.

The Input Format

The input file is precipitation.csv. CSV stands for comma separated value. Each column is delimited by a comma. It is a very common format used to export and import data. You can open it easily with Excel to view the rows and columns of data. Many of these will have a row at the top with the names of the columns separated by commas. There are only 2 columns in this file the date, and the amount of rainfall in mm. The date information is in YYYYMMDD format. Four characters for the year and 2 for the month and 2 for the day.

precipitation.csv

20091006,5.8

20091007,0.0

20091008,16.0

20091014,NA

20091015,3.0

20091016,0.0

This excerpt from the file shows 5.9 mm on October 6th, 2009. Notice on the 14th of October 2009 no data was recorded.

The Output Format

You will create a new output file that has each year month precipitation amounts totaled. Since our sample file has data from 20000101 to 20091231, the output file will have a total precipitation for each month from 2000 to 2009. The output file will also be a CSV file with 2 columns. A date column and a total precipitation column. The date column won’t require the day and will be in the format YYYYMM.

200001,9.4

200002,57.2

200003,67.6

200004,9.8

200005,68.7

200006,189.2

200007,149.79999999999998

The totals above show that the month of January in 2000 had a total of 9.4 mm of precipitation for the total month.

Month Totals Averaged The final part of your program will find the averages of total precipitation for each month. You will output the average for the total rainfall in Jan, Feb, etc.

Requirements

Ask the user for the precipitation file to read. If the file does not exist, show the error to the user and ask them to choose a new file.

Ask the user for the file to output to. If the file cannot be opened in write mode for any reason then warn the user and them to choose another file. One reason you may not be able to write to a file is if you give the name of a directory.

Any row from the input file that has NA or other non float values should be ignored.

Useful Modules and functions

.split() method is useful for splitting a string by a certain delimiter. In this case a comma.

The csv module can be used to help read csv files. It will automatically handle spliting the lines by the comma.

Example >>>================================RESTART================================ >>>

Enter the file with precipitation data==>notfound.csv

The file specified could not be found

Enter the file with precipitation data==>precipitation.csv

Enter the monthly data file to save to.==>test

The file specified had an IOError

Enter the monthly data file to save to.==>precip_monthly.csv

MonthlyTotalAverages

Month AvgPrecip

===== ==========

Jan 35.3500

Feb 52.3100

March 84.7300

April 95.1900

May 135.1300

June 157.2400

July 123.7800

Aug 122.1900

Sept 88.2500

Oct 98.0000

Nov 40.3200

Dec 45.8444

Explanation / Answer

CODE :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote