I am wondering why I can’t find the quartiles of my gpd column after splitting it. Do I need to divide quartiles into 4ths?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv(“country_data.csv”)
life_expectancy = data[“Life Expectancy”]
gdp = data[“GDP”]
life_expectancy_quartiles = np.quantile(life_expectancy, [0.25, 0.5 , 0.75])
median_gdp = np.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])
high_gdp_quartiles = np.quantile(high_gdp[“Life Expectancy”], [0.25, 0.5, 0.75])
This is the part of the code I think i’m having trouble on. I I thought that [0.25, 0.5, 0.75] would give the quartiles for Low GDP and High GDP. However it doesn’t seem to really work the way i want it to.
Thanks to whoever contributes.