import pandas as pd
# This is the same value that we computed in the last screen, but it's much simpler.
# The ease of using the .mean() method is great, but it's important to understand how the underlying data looks.
correct_mean_age = titanic_survival["age"].mean()
correct_mean_fare=titanic_survival["fare"].mean()
print(correct_mean_age)
# This is the same value that we computed in the last screen, but it's much simpler.
# The ease of using the .mean() method is great, but it's important to understand how the underlying data looks.
correct_mean_age = titanic_survival["age"].mean()
correct_mean_fare=titanic_survival["fare"].mean()
print(correct_mean_age)
print(correct_mean_fare)
another way:
passenger_survival = titanic_survival.pivot_table(index="pclass", values="survived", aggfunc=np.mean)
# First class passengers had a much higher survival chance
print(passenger_survival)
passenger_age=titanic_survival.pivot_table(index="pclass",values="age",aggfunc=np.mean)
print(passenger_age)