Feedback and Review of my US Medical Insurance Project

It would be much appreciated if somebody could review my project. I think is great (and it works), but I would love to hear any feedbacks and advices. It was hard for me, I am still new and I have relay more on the internet than my knockledge to be honest. Here it goes:

import csv

ages =
sexes =
bmis =
num_children =
smoker_statuses =
regions =
insurance_charges =

with open(‘insurance.csv’) as insurance_file:
insurance_csv = csv.DictReader(insurance_file)
for row in insurance_csv:
ages.append(int(row[‘age’]))
sexes.append(row[‘sex’])
bmis.append(float(row[‘bmi’]))
num_children.append(int(row[‘children’]))
smoker_statuses.append(row[‘smoker’])
regions.append(row[‘region’])
insurance_charges.append(float(row[‘charges’]))

class PatientData:
def init(self, ages, sexes, bmis, num_children, smoker_statuses, regions, insurance_charges):
self.ages = ages
self.sexes = sexes
self.bmis = bmis
self.num_children = num_children
self.smoker_statuses = smoker_statuses
self.regions = regions
self.insurance_charges = insurance_charges
# Method to calculate average insurance charges by gender
def average_insurance_by_gender(self):
women_charges = [self.insurance_charges[i] for i in range(len(self.sexes)) if self.sexes[i] == ‘female’]
men_charges = [self.insurance_charges[i] for i in range(len(self.sexes)) if self.sexes[i] == ‘male’]
avg_women_charges = sum(women_charges) / len(women_charges) if women_charges else 0
avg_men_charges = sum(men_charges) / len(men_charges) if men_charges else 0
return avg_women_charges, avg_men_charges
# Method to calculate BMI statistics
def bmi_statistics(self):
min_bmi = min(self.bmis) if self.bmis else 0
max_bmi = max(self.bmis) if self.bmis else 0
avg_bmi = sum(self.bmis) / len(self.bmis) if self.bmis else 0
return min_bmi, max_bmi, avg_bmi

# Method to calculate average yearly medical charges
def average_yearly_charges(self):
    avg_yearly_charges = sum(self.insurance_charges) / len(self.insurance_charges) if self.insurance_charges else 0
    return avg_yearly_charges

# Method to calculate difference in insurance charges between smokers and non-smokers
def insurance_difference_smoker_non_smoker(self):
    smoker_charges = [charge for smoker, charge in zip(self.smoker_statuses, self.insurance_charges) if smoker == 'yes']
    non_smoker_charges = [charge for smoker, charge in zip(self.smoker_statuses, self.insurance_charges) if smoker == 'no']
    avg_smoker_charges = sum(smoker_charges) / len(smoker_charges) if smoker_charges else 0
    avg_non_smoker_charges = sum(non_smoker_charges) / len(non_smoker_charges) if non_smoker_charges else 0
    difference = avg_smoker_charges - avg_non_smoker_charges
    return avg_smoker_charges, avg_non_smoker_charges, difference 

Create an instance of the InsuranceData class with the loaded data

patient_data = PatientData(
ages=ages,
sexes=sexes,
bmis=bmis,
num_children=num_children,
smoker_statuses=smoker_statuses,
regions=regions,
insurance_charges=insurance_charges
)

Perform analysis:

avg_women_charges, avg_men_charges = patient_data.average_insurance_by_gender()
min_bmi, max_bmi, avg_bmi = patient_data.bmi_statistics()
avg_yearly_charges = patient_data.average_yearly_charges()
avg_smoker_charges, avg_non_smoker_charges, difference = patient_data.insurance_difference_smoker_non_smoker()

Display results

print(f"Average insurance charges for women: ${avg_women_charges:.2f}“)
print(f"Average insurance charges for men: ${avg_men_charges:.2f}”)
print(f"Minimum BMI: {min_bmi:.2f}“)
print(f"Maximum BMI: {max_bmi:.2f}”)
print(f"Average BMI: {avg_bmi:.2f}“)
print(f"Average yearly medical charges: ${avg_yearly_charges:.2f}”)
print(f"Average insurance charges for smokers: ${avg_smoker_charges:.2f}“)
print(f"Average insurance charges for non-smokers: ${avg_non_smoker_charges:.2f}”)
print(f"Difference in insurance charges between smokers and non-smokers: ${difference:.2f}")