This is a really easy exercise, with a wide freedom to explore some knowledge related to pandas and numpy.
I appreciate your comments on it.
U.S. Medical Insurance Costs
import pandas as pd
import numpy as np
import csv
df = pd.read_csv(r’C:\00 Proyecto The Gender Bender\Python\Practica\Health insurance project\python-portfolio-project-starter-files\insurance.csv’)
reader = csv.DictReader(df)
print (df.head())
age sex bmi children smoker region charges
0 19 female 27.900 0 yes southwest 16884.92400
1 18 male 33.770 1 no southeast 1725.55230
2 28 male 33.000 3 no southeast 4449.46200
3 33 male 22.705 0 no northwest 21984.47061
4 32 male 28.880 0 no northwest 3866.85520
age
age = np.array(df.age)
media = np.mean(age)
media = np.mean(age)
text = 'La edad media de alguien con seguro es '+ str(media.round())
text = 'La edad media de alguien con seguro es '+ str(media.round())
xt
print(text)
La edad media de alguien con seguro es 39.0
import matplotlib as plt
import matplotlib
import matplotlib.pyplot as plt
agefemale =
agemale =
for i in range(len(df.sex)):
if df.sex[i] == ‘female’:
agefemale.append(df.age[i])
else:
agemale.append(df.age[i])
2
media = np.mean(agefemale)
text = 'La edad media de una mujer con seguro es '+ str(media.round())
print(text)
media = np.mean(agemale)
text2 = 'La edad media de un hombre con seguro es '+ str(media.round())
print(text2)
La edad media de una mujer con seguro es 40.0
La edad media de un hombre con seguro es 39.0
plt.hist(agemale, bins = 10, color = ‘green’)
plt.hist(agefemale, bins = 10, alpha = 0.8, color = ‘skyblue’)
plt.show()