# BEGIN PROVIDED CODE # ingest_data: given a file name and a field name, returns a list containing # all the data in the given file for the given field name import csv def ingest_data(filename, fieldname): file_object = open(filename, newline='') rows = csv.reader(file_object, delimiter=',') headers = next(rows) try: field_idx = headers.index(fieldname) except ValueError: print('The field name', fieldname, 'does not exist in the headers.') print('Here are the value field names in this file:') for h in headers: print(h) return data_list = [] count = 0 limit = 2000 # CHANGE LIMIT for line in rows: if (count >= limit): print('Too many entries, returning first', limit, 'entries.') return data_list try: field_value = line[field_idx] except IndexError: print('Skipping row #', count, 'because field does not exist') continue data_list.append(field_value) count = count + 1 return data_list # END PROVIDED CODE Sex = ingest_data("data.csv", "Sex") DescriptionofInjury = ingest_data("data.csv", "DescriptionofInjury") Location = ingest_data("data.csv", "Location") list1 = Sex list2 = DescriptionofInjury list3 = Location list4 =(Location, Sex) num_injection = list2.count("Injection") num_DrugUse = list2.count("Drug Use") num_Inhalation = list2.count("Inhalation") num_SubstanceAbuse = list2.count("Substance Abuse") num_Ingestion = list2.count("Ingestion") num_TookMedication = list2.count("Took Medication") num_hospital = list3.count("Hospital") num_residence = list3.count("Residence") num_other = list3.count("Other") num_males = list1.count("Male") num_females = list1.count("Female") def analyze_data(list1, list2): # if is 'Male': # print("No") # elif in Sex is 'Female': # print ("Yes") #return Sex