twoHelixestwoHelixes Start free

Datasets / World health and longevity

Life expectancy over time for five countries

Five named countries with very different starting points on one year axis show how their paths diverge over the same period.

Question how did life expectancy trend for Canada, Switzerland, Zimbabwe, Portugal and Cambodia?
Life expectancy by country02040608019901992199419961998200020022004200620082010201220142016201820202022YearSwitzerlandCanadaPortugalCambodiaZimbabwe
World health and longevity — 170 rows charted from 8,229, drawn as a line
How it decided
Finding the data13 ms

World health and longevity: 8,229 rows, 8 columns. year, country and life_expectancy for the five named countries; missing years are dropped.

Shaping the data10 ms

8,229 rows in, 170 out across 3 columns. Five named countries with very different starting points on one year axis show how their paths diverge over the same period.

Choosing the chart16 ms

line. A measure over time with one line per country, capped at five series so the lines stay distinguishable.

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.

result = (df[df["country"].isin(["Canada", "Switzerland", "Zimbabwe", "Portugal", "Cambodia"])].dropna(
    subset=["life_expectancy"])
          [["year", "country", "life_expectancy"]])

What it charted

170 rows out of 8,229, 3 columns. First 8 shown.

yearcountrylife_expectancy
1990Canada77.4333
1991Canada77.5939
1992Canada77.8525
1993Canada77.7251
1994Canada77.9007
1995Canada78.0206
1996Canada78.272
1997Canada78.4649