Skip to content

pycensus.census.countries.usa.elections_precinct

US precinct-level election results (Boston, San Francisco) resampled to H3 res 8 and census tracts/block groups.

load(city, scope, level='tract', **kw)

One frame: level in tract, blockgroup (index GEOID), h3 (index h3_cell, res 8) or precinct.

Example: load("boston", "national", level="tract").

Parameters:

Name Type Description Default
city str

City key.

required
scope str

"national", "state" or "municipal".

required
level str

"tract", "blockgroup", "h3" or "precinct".

'tract'
**kw

Passed to :func:load_all.

{}

Returns:

Type Description
DataFrame

The frame of that level.

load_all(city, scope, census_levels=('tract', 'blockgroup'), census_geometry=None, worldpop_path=None, cache_dir=None, municipal_stage='general')

All geographies for one election: {"precinct", "h3", "tract", "blockgroup"}.

census_geometry may map level -> GeoDataFrame(GEOID, geometry) to avoid TIGER downloads.

Parameters:

Name Type Description Default
city str

City key ("boston"...).

required
scope str

"national", "state" or "municipal".

required
census_levels

Census levels built.

('tract', 'blockgroup')
census_geometry Optional[Dict[str, GeoDataFrame]]

{level: polygons}.

None
worldpop_path Optional[str]

Explicit WorldPop raster.

None
cache_dir Optional[str]

Cache folder; None = the pycensus cache.

None
municipal_stage str

"general" or "prelim" (Boston municipal).

'general'