A briefing note before a country visit
"The RC is in N'Djamena on Monday. I need one page: electricity, child mortality and schooling in Chad, compared with the other Sahel countries."
The ask
The code
"""Briefing note: Chad against its Sahel neighbours, in one table and one sentence."""
import undata as un
SAHEL = ["Chad", "Niger", "Mali", "Burkina Faso", "Mauritania", "Sudan"]
MEASURES = {
"electricity %": "undata/sdg/EG_ACS_ELEC",
"under-5 deaths per 1,000": "undata/unicef/CME_MR.AGE--Y0T4",
"primary completion %": "undata/sdg/SE_TOT_CPLR.EDUCATION_LEVEL--ISCED11_1",
}
# One row per country, a value and a year per measure.
brief = un.compare(MEASURES, SAHEL).set_index("country")
print(brief.drop(columns="iso3").round(1).to_string(), "\n")
# The sentence for the note, worked out from the numbers rather than typed in.
RANK = {1: "", 2: "second-", 3: "third-", 4: "fourth-", 5: "fifth-", 6: "sixth-"}
chad = brief.loc["Chad"]
power_rank = int(brief["electricity %"].rank()["Chad"]) # 1 = the lowest
deaths_rank = int(brief["under-5 deaths per 1,000"].rank(ascending=False)["Chad"]) # 1 = highest
print(
f"In {chad['electricity % year']}, {chad['electricity %']:.0f}% of people in Chad had "
f"electricity, the {RANK[power_rank]}lowest of the six Sahel countries compared, and "
f"{chad['under-5 deaths per 1,000']:.0f} of every 1,000 children died before their fifth "
f"birthday, the {RANK[deaths_rank]}highest."
)The picture
Access to electricity
Under-5 deaths per 1,000 live births
Primary completion
What came back
01_country_briefing.py:13: MixedYearsWarning: The latest values for School completion rate [Education level=Primary education (ISCED11 - 1)] come from different years, 2014 to 2024. Values from different years are not directly comparable; the year column shows which is which. Pass within=N to keep only values from the past N years.
brief = un.compare(MEASURES, SAHEL).set_index("country")
electricity % electricity % year under-5 deaths per 1,000 under-5 deaths per 1,000 year primary completion % primary completion % year
country
Burkina Faso 34.0 2024 74.9 2024 60.3 2021
Chad 13.4 2024 97.3 2024 26.9 2019
Mali 49.5 2024 73.0 2024 47.5 2024
Mauritania 52.2 2024 36.9 2024 57.9 2015
Niger 21.3 2024 110.7 2024 35.8 2022
Sudan 66.0 2024 61.6 2024 65.4 2014
In 2024, 13% of people in Chad had electricity, the lowest of the six Sahel countries compared, and 97 of every 1,000 children died before their fifth birthday, the second-highest.In 2024, 13% of people in Chad had electricity, the lowest of the six Sahel countries compared, and 97 of every 1,000 children died before their fifth birthday, the second-highest.
- Mixed years, flagged. "Latest" school completion ranges across a decade between these six countries. The warning says so before the table can mislead anyone, and the year is on every row.
- Names as you write them. Six country names, no codes. Three indicators come back in one request.


