pycensus.census.countries.usa.elections_precinct.loader¶
US precinct-level election results for the study cities (Boston, San Francisco).
Elections (latest completed as of 2026-10; Nov 3 2026 not yet held):
=========== ============================== ============================== scope Boston (MA) San Francisco (CA) =========== ============================== ============================== national 2024 US President (precinct) 2024 US President (precinct) state 2022 Governor (precinct) 2022 Governor (precinct) municipal 2025-11-04 Mayor (precinct) 2024-11-05 Mayor (precinct, first-choice votes of the RCV) =========== ============================== ==============================
Sources¶
- MIT Election Data + Science Lab (MEDSL) precinct files on GitHub
(
MEDSL/2024-elections-officialindividual_states/{st}24.zip andMEDSL/2022-elections-officialindividual_states/2022-{st}-local-precinct-general.zip). MEDSL has no redaction in MA; CA has a handful of*cells (small-count redaction) that are treated as 0. - Boston mayor 2025: City of Boston official PDF "General Municipal Election -
November 4, 2025, Mayor, votes cast by precinct"
(boston.gov/sites/default/files/file/2025/11/2025-11-04-Mayor.pdf, parsed with
pdftotext -layout) and the registered-voter PDF (turnout). The general was effectively uncontested (Wu 93%, write-ins); the contested race was the 2025-09-09 preliminary (municipal_stage="prelim"). - Geometry: Boston Precinct Boundaries (data.boston.gov, 275 precincts) and SF
"Election Precincts - Current, Defined 2022" (DataSF d6x4-hefw, 514 precincts).
MEDSL SF precinct ids
1101/1101A(A = absentee) are merged to the 4-digit id.
Resampling: precinct -> H3 res 8 dasymetric with WorldPop 2025 100 m (see
:mod:pycensus.elections_common), then H3 -> census (TIGER 2020 tract / block
group) population weighted by the same pixels.
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 ( |
required |
scope
|
str
|
|
required |
census_levels
|
Census levels built. |
('tract', 'blockgroup')
|
|
census_geometry
|
Optional[Dict[str, GeoDataFrame]]
|
|
None
|
worldpop_path
|
Optional[str]
|
Explicit WorldPop raster. |
None
|
cache_dir
|
Optional[str]
|
Cache folder; |
None
|
municipal_stage
|
str
|
|
'general'
|
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
|
|
required |
level
|
str
|
|
'tract'
|
**kw
|
Passed to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The frame of that level. |