Hello!
After filling my lists with all the data from the insurance.csv file, I made a dictionary to order the data for each patient and it shows me up that the dict only have 47 patients out of 1338. (I checked every single list lenght and they all have 1338 objects).
What am I doing wrong? Or it’s just that it shows 47 but it has 1338 patients inside.
Thanks in advance!
This is the code (I also posted a photo where you can see both prints with 47 and 1338 lenght.
ages = load_list_data(ages, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "age")
sexes = load_list_data(sexes, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "sex")
bmi = load_list_data(bmi, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "bmi")
num_of_children = load_list_data(num_of_children, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "children")
smoker_status = load_list_data(smoker_status, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "smoker")
regions = load_list_data(regions, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "region")
insurance_cost = load_list_data(insurance_cost, "C:/Users/rodri.DESKTOP-RAT8004/Desktop/insurance.csv", "charges")
def create_dictionary(ages, sexes, bmi, num_of_children, smoker_status, regions, insurance_cost):
patients = dict()
num_patients = len(ages)
for i in range(num_patients):
patients[ages[i]] ={"Age" : ages[i],
"Sex" : sexes[i],
"BMI" : bmi[i],
"Number of children" : num_of_children[i],
"Smoker" : smoker_status[i],
"Region" : regions[i],
"Insurance charge" : insurance_cost[i]
}
return patients
patients = create_dictionary(ages, sexes, bmi, num_of_children, smoker_status, regions, insurance_cost)
len_patients = len(patients)
len_ages = len(ages)
print(len_patients)
print(len_ages)
# here it shows 47 for len_patients and 1338 for len_ages