Skip to content

pycensus.census.countries.spain.censo2021.loader

Loader for Spain's Censo 2021 (SDC21) source, returning a common-schema GeoDataFrame.

Technical aspects

Mirrors :mod:pycensus.census.countries.spain.ine.loader's shape (parquet cache via :mod:pycensus.cache, fetch-only-missing-columns), but reads from the SDC21 dissemination API (:mod:pycensus.census.countries.spain.censo2021.api) instead of the Padron Tempus3/PC-Axis sources. SDC21's API returns real census-section level breakdowns nationwide in a single request per category variable (see api.py module docstring for the live verification numbers); this loader aggregates those section rows up to municipality/ province/autonomous_community/nation the same way ine.loader._aggregate_to_level does for the Padron.

Only households, educationPrimaryOrLessPopulation, educationSecondaryPopulation, educationUniversityPopulation, laborForce, employedResidents, unemployedResidents, and foreignBornPopulation are implemented -- see spain/schema/censo2021_schema.json and this module's docstring for exactly which real SDC21 table/metric/variable/category each maps to. educationOtherTertiaryPopulation is intentionally not implemented: INE's SDC21 ID_ESREAL_GR5 variable only has one tertiary-education bucket ("Educacion Superior"), with no real way to split university from other tertiary without a different, unverified variable (ID_ESREAL_CNEDA, a finer detail code not yet mapped). Income (medianHouseholdIncome etc.) and commute-mode fields (carCommuters etc.) are also not implemented: SDC21 has no income variable at all (Spain's household income data comes from a separate, municipality-level-only source, the Atlas de Distribucion de Renta de los Hogares) and no commute-mode-of-transport variable.

Source

INE Censo 2021 SDC21 API: https://www.ine.es/Censo2021/api

load(aoi=None, regions=None, level='section', year='latest', api_key=None, cache_dir=None, cache=True, data_dir=None)

Load INE's Censo 2021 (SDC21) data as a common-schema GeoDataFrame.

Parameters:

Name Type Description Default
aoi Optional[GeoDataFrame]

Area of interest. Used to auto-detect regions if not given, and to clip the final result.

None
regions Optional[Union[str, List[str]]]

Region code(s) -- autonomous community code, province code, or 5-digit municipality code, matching level. Derived from aoi if omitted (aoi is then required).

None
level str

Standard geometry level name. Uses the same real, live-verified boundary levels as spain.ine.load (nation/autonomous_community/province/municipality/section), since both sources share :mod:pycensus.census.countries.spain.geography.

'section'
year Union[int, str]

Vintage year. SDC21's 2021 census is the only vintage (accepted for interface parity; not otherwise used).

'latest'
api_key Optional[str]

Not used -- SDC21's API requires no API key.

None
cache_dir Optional[str]

Root of pyCensus' parquet cache.

None
cache bool

If False, bypass the parquet cache entirely.

True
data_dir Optional[str]

Root directory for raw SDC21 downloads.

None

Returns:

Type Description
GeoDataFrame

GeoDataFrame with GEOID, geometry, and one censo2021_

GeoDataFrame

(canonicalized where a bare global-schema name applies) column per

GeoDataFrame

logical column implemented in

GeoDataFrame

mod:pycensus.census.countries.spain.censo2021.schema.

Raises:

Type Description
ValueError

If neither regions nor aoi is given.

NotImplementedError

If level resolves to a level without a real boundary source (see :mod:pycensus.census.countries.spain.geography).