Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-----Lab9-start.py# Open and read health data file one line at a time # Columns are # disease,increase,location,number,population,year file = open(health-no-head-sample.csv, r) # Process each line

image text in transcribed

-----Lab9-start.py# Open and read health data file one line at a time # Columns are # disease,increase,location,number,population,year

file = open("health-no-head-sample.csv", "r")

# Process each line of the file for aline in file: print (aline) values = aline.split(',') print (values)

# Close file file.close()

-----health-no-head.csv

MEASLES 200.75 ARIZONA 847 422000 1928 MEASLES 481.77 ARKANSAS 8899 1847000 1928 MEASLES 69.22 CALIFORNIA 3698 5344000 1928 MEASLES 206.98 COLORADO 2099 1014000 1928 MEASLES 634.95 CONNECTICUT 10014 1577000 1928 MEASLES 256.02 DELAWARE 597 233000 1928 MEASLES 535.63 DISTRICT OF COLUMBIA 2566 479000 1928 MEASLES 119.58 FLORIDA 1714 1433000 1928 MEASLES 159.73 GEORGIA 4637 2903000 1928 MEASLES 19.59 IDAHO 88 449000 1928 MEASLES 98.24 ILLINOIS 7444 7576000 1928 MEASLES 263.67 INDIANA 8470 3212000 1928 MEASLES 28.63 IOWA 702 2450000 1928 MEASLES 136.92 KANSAS 2533 1850000 1928 MEASLES 216.26 KENTUCKY 5551 2567000 1928 MEASLES 260.33 LOUISIANA 5373 2064000 1928 MEASLES 401.96 MAINE 3204 797000 1928 MEASLES 1089.39 MARYLAND 17539 1610000 1928 MEASLES 981.06 MASSACHUSETTS 41371 4217000 1928 MEASLES 547.55 MICHIGAN 25544 4665000 1928 MEASLES 79.13 MINNESOTA 2052 2592000 1928 MEASLES 0 MISSISSIPPI 0 1981000 1928 MEASLES 198.63 MISSOURI 7154 3601000 1928 MEASLES 139.86 MONTANA 757 541000 1928 MEASLES 78.95 NEBRASKA 1083 1371000 1928 MEASLES 272.15 NEW HAMPSHIRE 1274 468000 1928 MEASLES 797.14 NEW JERSEY 31631 3968000 1928 MEASLES 663.41 NEW MEXICO 2760 416000 1928 MEASLES 649.97 NEW YORK 75391 11599000 1928 MEASLES 1823.69 NORTH CAROLINA 56207 3082000 1928 MEASLES 55.73 NORTH DAKOTA 371 665000 1928 MEASLES 355.92 OHIO 23522 6608000 1928 MEASLES 268.71 OKLAHOMA 6298 2344000 1928 MEASLES 223.09 OREGON 2089 936000 1928 MEASLES 583.95 PENNSYLVANIA 57237 9802000 1928 MEASLES 735.32 RHODE ISLAND 4986 678000 1928 MEASLES 1138.49 SOUTH CAROLINA 19798 1739000 1928 MEASLES 160.16 SOUTH DAKOTA 1097 685000 1928 MEASLES 315.43 TENNESSEE 8276 2624000 1928 MEASLES 97.35 TEXAS 5524 5675000 1928 MEASLES 16.83 UTAH 85 504000 1928 MEASLES 334.8 VERMONT 1199 358000 1928 MEASLES 344.82 WASHINGTON 5348 1551000 1928 MEASLES 195.98 WEST VIRGINIA 3323 1696000 1928 MEASLES 124.61 WISCONSIN 3642 2923000 1928 MEASLES 227 WYOMING 500 220000 1928 POLIO 2.39 ALABAMA 62 2640000 1928 POLIO 2.61 ARIZONA 11 422000 1928

2. Use some if statements to add three filters to your program that let the user select exactly one state, disease and year to include in the report. Prompt the user to enter these values. Introduction This assignment lets you practice with reading from a file and manipulating lists. Preparation Enter state: Colorado Enter disease: shallpax Enter year: 1928 State Disease Number Year This assignment must be done in a standalone Python environment, not the textbook. See the Textbooks and Materials page for instructions on installing the compiler on your local computer or using Park's virtual desktop. COLORADO SMALLPOX 340 1928 Total 340 Unfortunately, this isn't very flexible. 1. Download the following all to the same folder: 1. The program Lab9-start.py 2. The data files health-no-head-sample.csv and health-no-head.csv The big data file contains records of some infectious diseases from 1928 to 2011. The small one only includes data from 3 years from 5 states. Run the python program. It should print something like this 3. Change your program so that if the user just hits return for a prompt, the program includes all the data for that field. For example: PLACES,26.SE,COLORUM , 12 , REALES", 20 ", "COLORADS, 2000', 'L '. 'l 'l Enter state (Empty means all): Colorado Enter disease (Empty means all): Enter year (Empty means all): 1928 State Disease Number Year TREASLES, 3.5', 'CONECTICUT, 2004, S . 22n'] 2,899 [REASLES", 26.02', 'OLL , 547, 230 , 232 "] COLORADO COLORADO COLORADO MEASLES POLIO SMALLPOX Total 1928 1929 1928 340 2,510 2. Make sure that you get output like this before starting the assignment or writing any additional code. Your program should run as expected using this small data set Directions Modify the program in the following ways: 1. Write each line as part of a table, include a header before the table, and a summary line at the end. Use a fixed width for each column (don't try to find the largest width like you did in the previous unit). You should end up with something like 4. Change the open statement in the program to use the full data set, health-no-head.csv. 5. Write down the answers to the following queries: 1. How many cases of Hepatitis A were reported in Utah in 2001? 2. How many cases of polio have been reported in California? 3. How many cases of all diseases were reported in 1956? 6. Add another feature to your program. This could be something like printing the highest and lowest numbers for each query or allowing the user to just type the first part of value, so that entering 20 for the year generates a table for years 2000, 2001, 2002, ... 2011, or entering D for a state gives information on Delaware and the District of Columbia. Or maybe leverage your previous assignment and make the column only as wide as they need to be for the data. Try to make it something useful. ers for each gue 2000, 2001, 2002verage State Disease Number Year 2.99 COLORADO CONNECTICUT DELANARE MEASLES MEASLES MEASLES 18,014 597 1928 1929 1928 7. Comment your code. Be sure to add a header comment to your program and any functions, and appropriate comments before other blocks of code. DELANARE DISTRICT OF COLUMBIA FLORIDA SMALLPOX SNALLPOX SMALLPOX Total 1930 1930 193e 52. 307 Not every field of the original line is used in the output. You will have to do some research about the formato function to print the number of cases with a comma. If you can't get the comma in the number column, move on and come back to that once you have more of the program written. The key is to have all the columns line up. 2. Use some if statements to add three filters to your program that let the user select exactly one state, disease and year to include in the report. Prompt the user to enter these values. Introduction This assignment lets you practice with reading from a file and manipulating lists. Preparation Enter state: Colorado Enter disease: shallpax Enter year: 1928 State Disease Number Year This assignment must be done in a standalone Python environment, not the textbook. See the Textbooks and Materials page for instructions on installing the compiler on your local computer or using Park's virtual desktop. COLORADO SMALLPOX 340 1928 Total 340 Unfortunately, this isn't very flexible. 1. Download the following all to the same folder: 1. The program Lab9-start.py 2. The data files health-no-head-sample.csv and health-no-head.csv The big data file contains records of some infectious diseases from 1928 to 2011. The small one only includes data from 3 years from 5 states. Run the python program. It should print something like this 3. Change your program so that if the user just hits return for a prompt, the program includes all the data for that field. For example: PLACES,26.SE,COLORUM , 12 , REALES", 20 ", "COLORADS, 2000', 'L '. 'l 'l Enter state (Empty means all): Colorado Enter disease (Empty means all): Enter year (Empty means all): 1928 State Disease Number Year TREASLES, 3.5', 'CONECTICUT, 2004, S . 22n'] 2,899 [REASLES", 26.02', 'OLL , 547, 230 , 232 "] COLORADO COLORADO COLORADO MEASLES POLIO SMALLPOX Total 1928 1929 1928 340 2,510 2. Make sure that you get output like this before starting the assignment or writing any additional code. Your program should run as expected using this small data set Directions Modify the program in the following ways: 1. Write each line as part of a table, include a header before the table, and a summary line at the end. Use a fixed width for each column (don't try to find the largest width like you did in the previous unit). You should end up with something like 4. Change the open statement in the program to use the full data set, health-no-head.csv. 5. Write down the answers to the following queries: 1. How many cases of Hepatitis A were reported in Utah in 2001? 2. How many cases of polio have been reported in California? 3. How many cases of all diseases were reported in 1956? 6. Add another feature to your program. This could be something like printing the highest and lowest numbers for each query or allowing the user to just type the first part of value, so that entering 20 for the year generates a table for years 2000, 2001, 2002, ... 2011, or entering D for a state gives information on Delaware and the District of Columbia. Or maybe leverage your previous assignment and make the column only as wide as they need to be for the data. Try to make it something useful. ers for each gue 2000, 2001, 2002verage State Disease Number Year 2.99 COLORADO CONNECTICUT DELANARE MEASLES MEASLES MEASLES 18,014 597 1928 1929 1928 7. Comment your code. Be sure to add a header comment to your program and any functions, and appropriate comments before other blocks of code. DELANARE DISTRICT OF COLUMBIA FLORIDA SMALLPOX SNALLPOX SMALLPOX Total 1930 1930 193e 52. 307 Not every field of the original line is used in the output. You will have to do some research about the formato function to print the number of cases with a comma. If you can't get the comma in the number column, move on and come back to that once you have more of the program written. The key is to have all the columns line up

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

Question

When should you avoid using exhaust brake select all that apply

Answered: 1 week ago