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()
W

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_2

Step: 3

blur-text-image_3

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

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

Identify the elements that make up the employee reward package.

Answered: 1 week ago

Question

Understand the purpose, value and drawbacks of the interview.

Answered: 1 week ago