Skip to content

pycensus.census.countries.usa.elections.columns

The one column-naming scheme for US election results, shared by every state, source and level.

{year}_{office}_{measure}            e.g.  2024_president_democrat_share,  2018_governor_other_share

Measures (all six always written together, so states and sources compare directly). Every ratio is over the people entitled to vote of the same unit -- the voting-age population (VAP), never over the votes cast:

eligible_voters    people with the right to vote in the unit: the voting-age population (summed when resampled)
total_votes        people who voted: all votes cast for the office (summed when resampled)
democrat_share     Democratic candidate's votes / VAP
republican_share   Republican candidate's votes / VAP
other_share        all other candidates' votes (third parties, independents, write-ins) / VAP
turnout            total_votes / eligible_voters  (= democrat_share + republican_share + other_share; non-voters are 1 - turnout)

VAP is population - under18Population (2020 Census) for now. Strictly the right to vote is held by citizens aged 18+; the Census Bureau's CVAP special tabulation (block groups, from the ACS) is the intended denominator and is not loaded yet, so non-citizens (and people barred by convictions) are still in the denominator. For elections before 2020 the 2020 count is used, so those ratios are approximate.

Offices use fixed names below no matter what the source calls them. democrat / republican means the major-party nominee of that party; fusion lines or a second party label for the same candidate are summed into the party. Years are election years (four digits).

column_name(year, office, measure)

Standard election column name <year>_<office>_<measure>.

Parameters:

Name Type Description Default
year int

Election year.

required
office str

Office key.

required
measure str

Measure key.

required

Returns:

Type Description
str

The column name.

Raises:

Type Description
ValueError

For an unknown office or measure.

parse_column(name)

(year, office, measure) of a standard election column, else None.

Parameters:

Name Type Description Default
name str

Column name.

required

votes_to_columns(year, office, dem, rep, total, voting_age_population)

The six standard columns from vote counts (arrays); rows with no votes or no voting-age population get NaN ratios.

Parameters:

Name Type Description Default
year int

Election year.

required
office str

Office key.

required
dem

Democratic votes.

required
rep

Republican votes.

required
total

Total votes.

required
voting_age_population

Voting-age population.

required