twoHelixestwoHelixes Start free

Datasets / World prosperity

Life expectancy against GDP per capita, latest year

One point per country, each at its most recent year where both measures are present, so gaps in either series cannot masquerade as zeros and pull a country to the corner of the plot.

Question is life expectancy related to GDP per capita in the latest year?
Life expectancy against GDP per capita0204060801983.812611616.15741320.2582963.598652842.632861.480594364.965541.3023620.7935Gdp Per Capita Ppp
World prosperity — 198 rows charted from 8,415, drawn as a scatter
How it decided
Finding the data23 ms

World prosperity: 8,415 rows, 8 columns. gdp_per_capita_ppp and life_expectancy in each country's latest year with both; missing values are dropped.

Shaping the data15 ms

8,415 rows in, 198 out across 2 columns. One point per country, each at its most recent year where both measures are present, so gaps in either series cannot masquerade as zeros and pull a country to the corner of the plot.

Choosing the chart4 ms

scatter. Two measures with no grouping is a scatter: one point per country shows the relationship directly.

Applying defaults1 ms

Palette, spacing, axis titles and legend placement applied. 0 issues found.

The transformation

This is the code, not a description of it — the chart above was drawn from what it returns, and the notebook download runs the same lines against the same file.

d = df.dropna(subset=["gdp_per_capita_ppp", "life_expectancy"])
latest = d.loc[d.groupby("country")["year"].idxmax()]
result = latest[["gdp_per_capita_ppp", "life_expectancy"]].reset_index(drop=True)

What it charted

198 rows out of 8,415, 2 columns. First 8 shown.

gdp_per_capita_ppplife_expectancy
1983.812666.0346
20501.64679.6019
15159.32476.261
64631.29784.0406
8597.53964.617
28712.39677.5976
27230.39677.3947
19402.75275.6827