pycensus.census.countries.canada.elections.loader¶
Election results for Toronto at the finest published unit, resampled to H3 res 8 and dissemination areas (DA 2021).
=========== =========================================== ============================== ====================== scope election native unit geometry =========== =========================================== ============================== ====================== national 45th federal general election, 2025-04-28 polling division (~4,600 in Elections Canada PD the city, incl. mobile polls) boundaries 2025 (SHP) state Ontario general election, 2025-02-27 polling division Elections Ontario PD shapefile 2025 municipal Toronto general election, 2022-10-24, mayor voting subdivision (~1,460) City of Toronto Open Data subdivisions 2022 =========== =========================================== ============================== ======================
(The 2023-06-26 Toronto mayoral by-election and the 2026 Ontario by-elections are NOT used: only regular general elections.)
Sources¶
- Federal: Elections Canada "45th General Election: Official Voting Results (raw data)" poll-by-poll CSV,
https://www.elections.ca/res/rep/off/ovrGE45/62/data_donnees/pollresults_resultatsbureau{FED}.zipand boundary filehttps://www.elections.ca/res/cir/mapsCorner/vector/PollingDivisionBoundaries_2025_SHP.zip(92.8 MB). - Ontario: Elections Ontario results portal API (
results.elections.on.ca/api/report-groups/48/report-outputs/1095/csv"Official Return from the Records", poll-by-poll;.../1096/csvcandidates with party code) and the "Polling Division Shapefile - 2025 General Election.zip" (elections.on.ca/content/dam/NGW/sitecontent/2017/preo/shapefiles/; limited-use data licence - check the licence on the download page before redistributing). - Toronto: Open Data "Elections - Official Results" 2022 poll-by-poll XLSX zip, and "Elections Subdivisions" 2022 GeoJSON.
- Census geometry: StatCan 2021 DA (
dissemination-area; www12.statcan.gc.ca is behind a Cloudflare challenge and is NOT bypassed: passcensus_geometryor rely on pycensus.canada.geography's ArcGIS cache).
Votes without polygon (federal special ballots "S/R", Ontario advance polls ADVnnn, Toronto subdivisions 97-99, polls
missing in the geometry) are pooled per riding/ward and spread over that district's polygons proportionally to registered electors.
total_votes = valid votes (federal/Ontario: candidates; Toronto: candidates incl. write-ins); turnout = (valid + rejected ballots)
/ electors for federal, absent for Ontario (advance polls have no electors) and Toronto (voter counts per subdivision only
partially cover pooled votes; reported as valid mayor votes / VOTER_COUNT, may exceed...: clipped to 1).
load_all(scope, census_geometry=None, worldpop_path=None, cache_dir=None, area=None)
¶
{"poll", "h3", "da"} frames for scope in national/state/municipal.
census_geometry: {"da": GeoDataFrame(GEOID|DAUID, geometry)} (2021 dissemination areas around Toronto).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
|
required |
census_geometry
|
Optional[Dict[str, GeoDataFrame]]
|
|
None
|
worldpop_path
|
Optional[str]
|
Explicit WorldPop raster. |
None
|
cache_dir
|
Optional[str]
|
Cache folder; |
None
|
area
|
Study area (shapely geometry, EPSG:4326 -- e.g. the union of the census geometry): the federal and Ontario elections take
every polling division whose representative point lies in it (all of the province publishes them); |
None
|
load(scope, level='da', **kw)
¶
One frame: level da (index GEOID = DAUID), h3 (index h3_cell, res 8) or poll.
Example: load("national", level="da").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
|
required |
level
|
str
|
|
'da'
|
**kw
|
Passed to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The frame of that level. |