Skip to content

pycensus.census.countries.mexico.inegi

Mexico Census 2020 (Censo de Poblacion y Vivienda 2020) source.

Importing this module registers the gdf.inegi GeoDataFrame accessor (see :mod:pycensus.accessors). Use :func:load to fetch data.

Technical aspects

Unlike US census data which has APIs, Mexico's INEGI Census 2020 data must be downloaded as files from INEGI's website. This module provides tools to: 1. Download census microdata and aggregated tables to data/mexico/ 2. Load and process the data into a common-schema GeoDataFrame 3. Cache processed data for efficient repeated access

Source

https://www.inegi.org.mx/programas/ccpv/2020/

load(aoi=None, states=None, level='municipality', year='latest', cache_dir=None, cache=True, data_dir=None)

Load INEGI Census 2020 data as a common-schema GeoDataFrame.

Parameters:

Name Type Description Default
aoi Optional[GeoDataFrame]

Area of interest. Used to auto-detect states if not given, and to clip the final result. Every state is checked since no national boundary layer is wired up to pre-filter (see :func:pycensus.mexico.geography.states_in_aoi).

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

State name(s)/abbreviation(s)/code(s) to load. Derived from aoi if omitted (aoi is then required).

None
level str

Standard geometry level name. "state", "municipality", "ageb", and "block" are implemented; other standard levels (e.g. "tract"/"blockgroup") fall back onto one of those via :data:pycensus.mexico.constants.LEVEL_FALLBACK where possible, else raise.

'municipality'
year Union[int, str]

Vintage year, or "latest". Only 2020 is available.

'latest'
cache_dir Optional[str]

Root of pyCensus' parquet cache (geometry + attribute columns, merged per level/region). Defaults to :func:pycensus.cache.default_cache_dir.

None
cache bool

If False, bypass the parquet cache entirely -- always fetch fresh and don't persist the result. INEGI's own raw ITER/Marco Geoestadistico downloads (:mod:pycensus.mexico.api, :mod:pycensus.mexico.geography) are cached on disk independently of this flag, since re-downloading multi-MB per-state files on every call would be impractical.

True
data_dir Optional[str]

Base directory for INEGI's raw downloaded files (ITER CSVs, Marco Geoestadistico zips). Defaults to :data:pycensus.mexico.constants.DEFAULT_DATA_DIR.

None

Returns:

Type Description
GeoDataFrame

GeoDataFrame with GEOID, geometry, and one inegi_-prefixed

GeoDataFrame

column per logical column in :data:pycensus.mexico.inegi.schema.SCHEMA.

Raises:

Type Description
ValueError

If neither states nor aoi is given, or level has no implemented data source.