undata reference¶
undata is a Python package for the UN System Data Commons: type a country’s name, get a table of UN statistics with the unit, year and source on every row. This is the reference for every function. For worked examples with real output, see the use cases.
pip install undata # tables and Excel
pip install "undata[charts]" # + charts
pip install "undata[all]" # + interactive charts and the AI connector
import undata as un
table = un.latest("3.1.1", "LDCs", within=10) # each LDC's latest maternal mortality ratio
print(un.describe(table)) # a sentence for the report
un.save(table, "maternal-mortality.xlsx") # with sources on their own sheet
Conventions used everywhere¶
Places. Wherever a function asks for countries you can pass a name the way you would
write it ("Viet Nam", "Vietnam", "VNM"), a list of names, an M49 region
("Southern Asia", "Africa"), or a UN group ("LDCs", "LLDCs", "SIDS").
Regions and groups expand to their member countries. Tables use the UN’s official names.
Indicators. An indicator id from undata.search() (such as
"undata/sdg/SH_STA_MORT.SEX--F"), or an SDG number ("3.1.1") when one series
reports it. When several do, the error lists them.
Tables. Functions return pandas.DataFrame objects with one row per value,
and keep their metadata (sources, the years asked for, what was missing) in
table.attrs, so undata.describe(), undata.cite(), undata.save() and
undata.chart() know where the numbers came from.
Warnings. Data problems (missing countries, values from different years, old values) are reported as warnings, never as zeros. See Settings, errors and the low-level layer.
Reference
undata is an unofficial Nerd Lab project, not affiliated with or endorsed by the United Nations. The data belongs to the agencies that publish it.