Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python: file = open(health-no-head-sample.csv, r) file = open(head-no-head.csv, r) # Process each line of the file for aline in file: ----print (aline) ----values = aline.split(',')

Python:

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

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

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

# Close file file.close()

____________________________________

output:

MEASLES,206.98,COLORADO,2099,1014000,1928 ['MEASLES', '206.98', 'COLORADO', '2099', '1014000', '1928 '] MEASLES,634.95,CONNECTICUT,10014,1577000,1928 ['MEASLES', '634.95', 'CONNECTICUT', '10014', '1577000', '1928 '] MEASLES,256.02,DELAWARE,597,233000,1928 ['MEASLES', '256.02', 'DELAWARE', '597', '233000', '1928 '] MEASLES,535.63,DISTRICT OF COLUMBIA,2566,479000,1928 ['MEASLES', '535.63', 'DISTRICT OF COLUMBIA', '2566', '479000', '1928 '] MEASLES,119.58,FLORIDA,1714,1433000,1928 ['MEASLES', '119.58', 'FLORIDA', '1714', '1433000', '1928 '] POLIO,7.04,COLORADO,71,1014000,1928 ['POLIO', '7.04', 'COLORADO', '71', '1014000', '1928 '] POLIO,4.53,CONNECTICUT,72,1577000,1928 ['POLIO', '4.53', 'CONNECTICUT', '72', '1577000', '1928 '] POLIO,3.44,DELAWARE,8,233000,1928 ['POLIO', '3.44', 'DELAWARE', '8', '233000', '1928 '] POLIO,6.92,DISTRICT OF COLUMBIA,33,479000,1928 ['POLIO', '6.92', 'DISTRICT OF COLUMBIA', '33', '479000', '1928 '] POLIO,1.47,FLORIDA,21,1433000,1928 ['POLIO', '1.47', 'FLORIDA', '21', '1433000', '1928 '] SMALLPOX,33.58,COLORADO,340,1014000,1928 ['SMALLPOX', '33.58', 'COLORADO', '340', '1014000', '1928 '] SMALLPOX,10.19,CONNECTICUT,161,1577000,1928 ['SMALLPOX', '10.19', 'CONNECTICUT', '161', '1577000', '1928 '] SMALLPOX,0.86,DELAWARE,2,233000,1928 ['SMALLPOX', '0.86', 'DELAWARE', '2', '233000', '1928 '] SMALLPOX,2.1,DISTRICT OF COLUMBIA,10,479000,1928 ['SMALLPOX', '2.1', 'DISTRICT OF COLUMBIA', '10', '479000', '1928 '] SMALLPOX,10.99,FLORIDA,157,1433000,1928 ['SMALLPOX', '10.99', 'FLORIDA', '157', '1433000', '1928 '] MEASLES,74.24,COLORADO,748,1008000,1929 ['MEASLES', '74.24', 'COLORADO', '748', '1008000', '1929 '] MEASLES,614.82,CONNECTICUT,9800,1594000,1929 ['MEASLES', '614.82', 'CONNECTICUT', '9800', '1594000', '1929 '] MEASLES,239.82,DELAWARE,566,236000,1929 ['MEASLES', '239.82', 'DELAWARE', '566', '236000', '1929 '] MEASLES,94.2,DISTRICT OF COLUMBIA,455,483000,1929 ['MEASLES', '94.2', 'DISTRICT OF COLUMBIA', '455', '483000', '1929 '] MEASLES,78.01,FLORIDA,1127,1445000,1929 ['MEASLES', '78.01', 'FLORIDA', '1127', '1445000', '1929 '] POLIO,1.3,COLORADO,13,1008000,1929 ['POLIO', '1.3', 'COLORADO', '13', '1008000', '1929 '] POLIO,1.32,CONNECTICUT,21,1594000,1929 ['POLIO', '1.32', 'CONNECTICUT', '21', '1594000', '1929 '] POLIO,2.1,DELAWARE,5,236000,1929 ['POLIO', '2.1', 'DELAWARE', '5', '236000', '1929 '] POLIO,1.26,DISTRICT OF COLUMBIA,6,483000,1929 ['POLIO', '1.26', 'DISTRICT OF COLUMBIA', '6', '483000', '1929 '] POLIO,2.38,FLORIDA,34,1445000,1929 ['POLIO', '2.38', 'FLORIDA', '34', '1445000', '1929 '] SMALLPOX,83.77,COLORADO,844,1008000,1929 ['SMALLPOX', '83.77', 'COLORADO', '844', '1008000', '1929 '] SMALLPOX,2.69,CONNECTICUT,43,1594000,1929 ['SMALLPOX', '2.69', 'CONNECTICUT', '43', '1594000', '1929 '] SMALLPOX,0.84,DELAWARE,2,236000,1929 ['SMALLPOX', '0.84', 'DELAWARE', '2', '236000', '1929 '] SMALLPOX,0,DISTRICT OF COLUMBIA,0,483000,1929 ['SMALLPOX', '0', 'DISTRICT OF COLUMBIA', '0', '483000', '1929 '] SMALLPOX,2.52,FLORIDA,36,1445000,1929 ['SMALLPOX', '2.52', 'FLORIDA', '36', '1445000', '1929 '] MEASLES,1132.76,COLORADO,11781,1040000,1930 ['MEASLES', '1132.76', 'COLORADO', '11781', '1040000', '1930 '] MEASLES,112.23,CONNECTICUT,1810,1613000,1930 ['MEASLES', '112.23', 'CONNECTICUT', '1810', '1613000', '1930 '] MEASLES,109.25,DELAWARE,261,239000,1930 ['MEASLES', '109.25', 'DELAWARE', '261', '239000', '1930 '] MEASLES,182.1,DISTRICT OF COLUMBIA,889,488000,1930 ['MEASLES', '182.1', 'DISTRICT OF COLUMBIA', '889', '488000', '1930 '] MEASLES,356.59,FLORIDA,5245,1471000,1930 ['MEASLES', '356.59', 'FLORIDA', '5245', '1471000', '1930 '] POLIO,6.25,COLORADO,65,1040000,1930 ['POLIO', '6.25', 'COLORADO', '65', '1040000', '1930 '] POLIO,4.57,CONNECTICUT,74,1613000,1930 ['POLIO', '4.57', 'CONNECTICUT', '74', '1613000', '1930 '] POLIO,2.52,DELAWARE,6,239000,1930 ['POLIO', '2.52', 'DELAWARE', '6', '239000', '1930 '] POLIO,1.8,DISTRICT OF COLUMBIA,9,488000,1930 ['POLIO', '1.8', 'DISTRICT OF COLUMBIA', '9', '488000', '1930 '] POLIO,0.84,FLORIDA,12,1471000,1930 ['POLIO', '0.84', 'FLORIDA', '12', '1471000', '1930 '] SMALLPOX,54.03,COLORADO,562,1040000,1930 ['SMALLPOX', '54.03', 'COLORADO', '562', '1040000', '1930 '] SMALLPOX,0,CONNECTICUT,0,1613000,1930 ['SMALLPOX', '0', 'CONNECTICUT', '0', '1613000', '1930 '] SMALLPOX,0,DELAWARE,0,239000,1930 ['SMALLPOX', '0', 'DELAWARE', '0', '239000', '1930 '] SMALLPOX,0,DISTRICT OF COLUMBIA,0,488000,1930 ['SMALLPOX', '0', 'DISTRICT OF COLUMBIA', '0', '488000', '1930 '] SMALLPOX,1.94,FLORIDA,28,1471000,1930 ['SMALLPOX', '1.94', 'FLORIDA', '28', '1471000', '1930 '] 

________________________________________________________________________________________-

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 (dont try to find the largest width like you did in the previous unit). You should end up with something like
    State Disease Number Year COLORADO MEASLES 2,099 1928 CONNECTICUT MEASLES 10,014 1928 DELAWARE MEASLES 597 1928  DELAWARE SMALLPOX 0 1930 DISTRICT OF COLUMBIA SMALLPOX 0 1930 FLORIDA SMALLPOX 28 1930 Total 52,307 
    Not every field of the original line is used in the output. You will have to do some research about the .format() function to print the number of cases with a comma. If you cant 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.
    Enter state: Colorado Enter disease: smallpox Enter year: 1928 State Disease Number Year COLORADO SMALLPOX 340 1928 Total 340 
    Unfortunately, this isnt very flexible.
  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:
    Enter state (Empty means all): Colorado Enter disease (Empty means all): Enter year (Empty means all): 1928 State Disease Number Year COLORADO MEASLES 2,099 1928 COLORADO POLIO 71 1928 COLORADO SMALLPOX 340 1928 Total 2,510 
    Your program should run as expected using this small data set
  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 that print the highest and lowest numbers for each query
  7. Comment your code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions

Question

Are my points each supported by at least two subpoints?

Answered: 1 week ago