Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 14, 2020 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/6bcf7a1675be4f57f43aa9b9903f60e1 to your computer and use it in GitHub Desktop.
Save codecademydev/6bcf7a1675be4f57f43aa9b9903f60e1 to your computer and use it in GitHub Desktop.
Codecademy export
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