Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

where am i going wrong on this: # Open and read health data file one line at a time # Columns are # disease,increase,location,number,population,year import

where am i going wrong on this: # Open and read health data file one line at a time
# Columns are
# disease,increase,location,number,population,year
import csv
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)
def load_data(health_no_head):
with open(health_no_head, newline='') as file:
reader = csv.DictReader(file)
return list(reader)
def format_number(number):
return '{:,}'.format(number)
def display_table(data):
header =["State", "Disease", "Number", "Year"]
print("{:<20}{:<20}{:<15}{:<10}".format(*header))
for row in data:
print("{:<20}{:<20}{:<15}{:<10}".format(row['State'], row['Disease'], format_number(int(row['Number'])), row['Year']))
def filter_data(data, state=None, disease=None, year=None):
filtered_data = data
if state:
filtered_data =[row for row in filtered_data if row['State'].lower()== state.lower()]
if disease:
filtered_data =[row for row in filtered_data if row['Disease'].lower()== disease.lower()]
if year:
filtered_data =[row for row in filtered_data if row['Year']== year]
return filtered_data
def get_input(prompt):
user_input = input(prompt)
if user_input.strip()=="":
return None
return user_input.strip()
def main():
data = load_data('health_no_head.csv')
state = get_input("Enter state (Empty means all): ")
disease = get_input("Enter disease (Empty means all): ")
year = get_input("Enter year (Empty means all): ")
filtered_data = filter_data(data, state, disease, year)
display_table(filtered_data)
if filtered_data:
total_cases = sum(int(row['Number']) for row in filtered_data)
highest_cases = max(filtered_data, key=lambda x: int(x['Number']))
lowest_cases = min(filtered_data, key=lambda x: int(x['Number']))
print("
Total cases:", format_number(total_cases))
print("Highest number of cases:", highest_cases['Number'],"in", highest_cases['State'], highest_cases['Disease'], highest_cases['Year'])
print("Lowest number of cases:", lowest_cases['Number'],"in", lowest_cases['State'], lowest_cases['Disease'], lowest_cases['Year'])
if __name__=="__main__":
main()
# Close file
file.close()
MEASLES 206.98 COLORADO 209910140001928
MEASLES 634.95 CONNECTICUT 1001415770001928
MEASLES 256.02 DELAWARE 5972330001928
MEASLES 535.63 DISTRICT OF COLUMBIA 25664790001928
MEASLES 119.58 FLORIDA 171414330001928
POLIO 7.04 COLORADO 7110140001928
POLIO 4.53 CONNECTICUT 7215770001928
POLIO 3.44 DELAWARE 82330001928
POLIO 6.92 DISTRICT OF COLUMBIA 334790001928
POLIO 1.47 FLORIDA 2114330001928
SMALLPOX 33.58 COLORADO 34010140001928
SMALLPOX 10.19 CONNECTICUT 16115770001928
SMALLPOX 0.86 DELAWARE 22330001928
SMALLPOX 2.1 DISTRICT OF COLUMBIA 104790001928
SMALLPOX 10.99 FLORIDA 15714330001928
MEASLES 74.24 COLORADO 74810080001929
MEASLES 614.82 CONNECTICUT 980015940001929
MEASLES 239.82 DELAWARE 5662360001929
MEASLES 94.2 DISTRICT OF COLUMBIA 4554830001929
MEASLES 78.01 FLORIDA 112714450001929
POLIO 1.3 COLORADO 1310080001929
POLIO 1.32 CONNECTICUT 2115940001929
POLIO 2.1 DELAWARE 52360001929
POLIO 1.26 DISTRICT OF COLUMBIA 64830001929
POLIO 2.38 FLORIDA 3414450001929
SMALLPOX 83.77 COLORADO 84410080001929
SMALLPOX 2.69 CONNECTICUT 4315940001929
SMALLPOX 0.84 DELAWARE 22360001929
SMALLPOX 0 DISTRICT OF COLUMBIA 04830001929
SMALLPOX 2.52 FLORIDA 3614450001929
MEASLES 1132.76 COLORADO 1178110400001930
MEASLES 112.23 CONNECTICUT 181016130001930
MEASLES 109.25 DELAWARE 2612390001930
MEASLES 182.1 DISTRICT OF COLUMBIA 8894880001930
MEASLES 356.59 FLORIDA 524514710001930
POLIO 6.25 COLORADO 6510400001930
POLIO 4.57 CONNECTICUT 7416130001930
POLIO 2.52 DELAWARE 62390001930
POLIO 1.8 DISTRICT OF COLUMBIA 94880001930
POLIO 0.84 FLORIDA 1214710001930
SMALLPOX 54.03 COLORADO 562104000019

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

Students also viewed these Databases questions

Question

Find any intercepts. xy - x + 4y = 0

Answered: 1 week ago

Question

Does it have correct contact information?

Answered: 1 week ago