Review My Python Portfolio Project: U.S Medical Insurance Costs

It wouldnt let me bring the IPYNB file over and this is my first time posting a review so i didnt know how else to other than just copy pastaing that SoB right here.

import csv

ages =
sexes =
bmis =
children =
smoker_statuses =
regions =
charges =

with open(“insurance.csv”) as insurance_data_csv:
insurance_reader = csv.DictReader(insurance_data_csv)
for entry in insurance_reader:

average_age = sum(ages) / len(ages)

from collections import Counter
region_counter = Counter(regions)
most_common = region_counter.most_common(1)
print(f"Most common region: {most_common}")

smoker_charges = [charge for charge, smoker in zip(charges, smoker_statuses) if smoker == “yes”]
non_smoker_charges = [charge for charge, smoker in zip(charges, smoker_statuses) if smoker == “no”]

average_smoker_charges = sum(smoker_charges) / len(smoker_charges)
average_non_smoker_charges = sum(non_smoker_charges) / len(non_smoker_charges)

charge_difference = average_smoker_charges - average_non_smoker_charges

print(f"Average charges for smokers: {average_smoker_charges:.2f}“)
print(f"Average charges for non-smokers: {average_non_smoker_charges:.2f}”)
print(f"Difference in average charges between smokers and non-smokers: {charge_difference:.2f}")

ages_with_children = [age for age, child_count in zip(ages, children) if child_count >= 1]

average_age_with_children = sum(ages_with_children) / len(ages_with_children)

print(f"Average age for individuals with at least one child: {average_age_with_children:.2f}")

from collections import defaultdict
region_totals = defaultdict(float)
region_counts = defaultdict(int)

for region, charge in zip(regions, charges):
region_totals[region] += charge
region_counts[region] += 1

average_charges_by_region = {region: total / count for region, total, count in zip(region_totals.keys(), region_totals.values(), region_counts.values())}

most_expensive_region = max(average_charges_by_region, key=average_charges_by_region.get)

print(f"The most expensive region is {most_expensive_region} with an average charge of {average_charges_by_region[most_expensive_region]:.2f}")

im just now realizing the insurance csv file wont be available to you guys. im sorry :frowning:

and my indentation got messed up on the copy over. Feelsbadman