Skip to content

pycensus.census.countries.taiwan.elections.loader

CEC (中央選舉委員會) election database loader: results per village (村里, native resolution) -> H3 res 8.

https://db.cec.gov.tw/ElecTable/Election/ElectionList (keyless static JSON behind the Nuxt app, discovered from its JS bundle):

list https://db.cec.gov.tw/static/elections/list/ELC_{subject}.json (themes: theme_id, session, vote_date, legislator type) data https://db.cec.gov.tw/static/elections/data/{tickets|profiles}/ELC/{subject}/{legis}/{theme_id}/L/{prv}_{city}_00_000_0000.json

L = village level; one file holds every village of a county/city (dict keyed by district). tickets = votes per candidate/party and village, profiles = valid/invalid/cast ballots and eligible voters (votable_population) per village. CEC prv+city+dept+li maps to MOI's 11-digit village GEOID as prv(2)+city(3)+dept(3)+li[1:](3) (verified 456/456 for Taipei vs MOI RIS).

Subjects: P0 president (legis 00), L0 legislators (L4 = nationwide party-list vote used for load_legislative), C1/C2 mayor of special municipality / county-city (00), T1/T2 council of special municipality / county-city (T1 = regional constituencies; indigenous seats T2/T3 excluded).

Left/right: see schema/taiwan_elections_blocs.json (DPP & progressive small parties = left, KMT/PFP/NP = right, TPP/independents = other). H3: village polygons (OSM Overpass via taiwan.geography.load_boundaries('village')) -> res-8 cells, AREA-WEIGHTED (see pycensus.electoral).

load_election(subject, legis, year, tag, counties=('63000',), level='village', data_dir=None, party_threshold=0.03, with_h3=True, candidate_party_column=True)

Generic loader. subject/legis as in the module docstring (for county-vs-municipality pairs C1/C2, T1/T2 the right one is chosen per county).

Returns ElectionResult(census, h3): census keyed by GEOID (11-digit village; level='district' 8-digit, 'county_city' 5-digit) with elec_<tag>_* columns; h3 keyed by h3_cell (res 8) with the same shares plus cnt_* count columns.

Parameters:

Name Type Description Default
subject str

CEC election subject code.

required
legis str

CEC constituency code.

required
year int

Election year.

required
tag str

Column tag (national_2024...).

required
counties Iterable[str]

5-digit county codes.

('63000',)
level str

"village", "district" or "county_city".

'village'
data_dir Optional[str]

Folder of the raw downloads; None = the pycensus cache.

None
party_threshold float

Parties above this share get their own columns.

0.03
with_h3 bool

Also build the H3 frame.

True
candidate_party_column bool

Use the candidate's party as the party.

True

load_presidential(year=2024, **kw)

President/VP ticket vote (party of the presidential candidate). Columns elec_national_<year>_*.

Parameters:

Name Type Description Default
year int

Election year.

2024
**kw

Passed to :func:load_election.

{}

Returns:

Name Type Description
The ElectionResult

class:ElectionResult.

load_legislative(year=2024, **kw)

Legislative Yuan nationwide party-list vote (L4). Columns elec_national_<year>leg_* (suffix leg avoids clashing with the presidential).

Parameters:

Name Type Description Default
year int

Election year.

2024
**kw

Passed to :func:load_election.

{}

Returns:

Name Type Description
The ElectionResult

class:ElectionResult.

load_mayor(year=2022, **kw)

Mayor / county magistrate election. Columns elec_municipal_<year>_* (party = candidate's party; leading independents get own column).

Parameters:

Name Type Description Default
year int

Election year.

2022
**kw

Passed to :func:load_election.

{}

Returns:

Name Type Description
The ElectionResult

class:ElectionResult.

load_council(year=2022, **kw)

City/county council (regional constituencies, candidate votes summed by party). Columns elec_municipal_<year>council_*.

Parameters:

Name Type Description Default
year int

Election year.

2022
**kw

Passed to :func:load_election.

{}

Returns:

Name Type Description
The ElectionResult

class:ElectionResult.