-
-
Save codecademydev/6bcf7a1675be4f57f43aa9b9903f60e1 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecademylib3_seaborn | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
data = pd.read_csv("country_data.csv") | |
print(data.head()) | |
life_expectancy = data["Life Expectancy"] | |
life_expectancy_quartiles = np.quantile(life_expectancy, [0.25, 0.5, 0.75]) | |
plt.hist(life_expectancy) | |
plt.show() | |
gdp = data["GDP"] | |
median_gdp = np.quantile(gdp, 0.5) | |
print(median_gdp) | |
low_gdp = data[data['GDP'] <= median_gdp] | |
high_gdp = data[data['GDP'] > median_gdp] | |
low_gdp_quartiles = np.quantile(low_gdp["Life Expectancy"], [0.25, 0.5, 0.75]) | |
print(low_gdp_quartiles) | |
high_gdp_quartiles = np.quantile(high_gdp["Life Expectancy"], [0.25, 0.5, 0.75]) | |
print(high_gdp_quartiles) | |
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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment