import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#1
data = pd.read_csv("country_data.csv")
print(data.head())
Country Life Expectancy GDP
0 Afghanistan 58.19375 340.015425
1 Albania 75.15625 2119.726679
2 Algeria 73.61875 2847.853392
3 Angola 49.01875 1975.143045
4 Antigua and Barbuda 75.05625 9759.305728
life_expectancy = data["Life Expectancy"]
#2-3
life_expectancy_quartiles = np.quantile(life_expectancy, [0.25, 0.5, 0.75])
print(life_expectancy_quartiles)
[62.325 72.525 75.4421875]
#4
plt.hist(life_expectancy)
plt.show()
#5-6
dp = data["GDP"]
#7
median_gdp = np.quantile(gdp, 0.5)
print(median_gdp)
2938.0781155
#8
low_gdp = data[data['GDP'] <= median_gdp]
high_gdp = data[data['GDP'] > median_gdp]
#9
low_gdp_quartiles = np.quantile(low_gdp["Life Expectancy"], [0.25, 0.5, 0.75])
print(low_gdp_quartiles)
[56.3375 64.34375 71.7375 ]
#10
high_gdp_quartiles = np.quantile(high_gdp["Life Expectancy"], [0.25,0.5,0.75])
print(high_gdp_quartiles)
[72.965625 75.15625 80.521875]
#11
plt.hist(high_gdp["Life Expectancy"], alpha = 0.5, label = "High GDP")
plt.hist(low_gdp["Life Expectancy"], alpha = 0.5, label = "Low GDP")
plt.legend()
plt.show()
#FINAL..