My US Insurance Project

import csv

age_list =
sex_list =
bmi_list =
children_list =
smoker_list =
region_list =
charges_list =

def load_list_data(lst, csv_file, column_name):
with open(‘insurance.csv’) as csv_info:
csv_dict = csv.DictReader(csv_info)
for row in csv_dict:
lst.append(row[column_name])
return lst

load_list_data(age_list, ‘insurance.csv’, ‘age’)
load_list_data(sex_list, ‘insurance.csv’, ‘sex’)
load_list_data(bmi_list, ‘insurance.csv’, ‘bmi’)
load_list_data(children_list, ‘insurance.csv’, ‘children’)
load_list_data(smoker_list, ‘insurance.csv’, ‘smoker’)
load_list_data(region_list, ‘insurance.csv’, ‘region’)
load_list_data(charges_list, ‘insurance.csv’, ‘charges’)

class PatientInfo:
def init(self, patients_ages, patients_sexes, patients_bmis, patients_num_children,
patients_smoker_statuses, patients_regions, patients_charges):
self.patients_ages = patients_ages
self.patients_sexes = patients_sexes
self.patients_bmis = patients_bmis
self.patients_num_children = patients_num_children
self.patients_smoker_statuses = patients_smoker_statuses
self.patients_regions = patients_regions
self.patients_charges = patients_charges

def analyze_age(self):
    total = 0
    for age in self.patients_ages:
        total += int(age)
    return "Average Patient Age: " + str(round(total / len(self.patients_ages), 2)) + " years"

def analyze_sex(self):
    male = 0
    female = 0
    for sex in self.patients_sexes:
        if sex == 'male':
            male += 1
        elif sex == 'female':
            female += 1
    print('Total males: {}'.format(male))
    print('Total females: {}'.format(female))

def unique_region(self):
    new_list = []
    for region in self.patients_regions:
        if region not in new_list:
            new_list.append(region)
    return new_list

def average_charges(self):
    total = 0
    for charge in self.patients_charges:
        total += float(charge)
    return "Average Yearly Medical Insurance Charges: {}".format(
        str(round(total / len(self.patients_charges), 2)) + " dollars.")

def creat_dictionary(self):
    new_dict = {'age': [int(age) for age in self.patients_ages], 'sex': self.patients_sexes,
                'bmi': self.patients_bmis, 'children': self.patients_num_children,
                'smoker': self.patients_smoker_statuses, 'region': self.patients_regions,
                'charges': self.patients_charges}

    return new_dict

patient_info = PatientInfo(patients_ages=age_list, patients_sexes=sex_list, patients_charges=charges_list,
patients_regions=region_list, patients_bmis=bmi_list, patients_num_children=children_list,
patients_smoker_statuses=smoker_list)

age = patient_info.analyze_age()
print(age)

print(patient_info.analyze_sex())

unique_regions = patient_info.unique_region()
print(unique_regions)

average_charges = patient_info.average_charges()
print(average_charges)

new_dictionary = patient_info.creat_dictionary()
for key, value in new_dictionary.items():
print(key, value)