Hi,
I am trying to create a patient info dictionary.
However, my code is only creating a dictionary containing one individual’s medical info.
I am not quite sure how to get it to iterate through all of the data. My suspicion is that it needs to iterate through each line of data in the csv, but I am not quite sure on how to do that…
The data I am reading presents itself with the following format:
[‘42’, ‘male’, ‘31.255’, ‘0’, ‘no’, ‘northwest’, ‘6358.77645’]
[‘25’, ‘male’, ‘29.7’, ‘3’, ‘yes’, ‘southwest’, ‘19933.458’]
[‘57’, ‘male’, ‘18.335’, ‘0’, ‘no’, ‘northeast’, ‘11534.87265’]
…
def create_patient_info_dict(csv_file):
with open(csv_file) as csv_data: # opens the csv without DictReader
csv_data_reader = csv.reader(csv_data)
patient_info_dict = {}
for info in csv_data_reader:
patient_info_dict = {"Age": info[0],
"Sex": info[1],
"BMI": info[2],
"Number of Children": info[3],
"Smoker Status": info[4],
"Region": info[5],
"Insurance Charge": info[6]}
return patient_info_dict
patient_info = create_patient_info_dict("insurance.csv")
print(patient_info)
Thank you very much for your help!