A Colorado Board of Elections employee outlined the following tasks to complete the election audit of a recent local congressional election.
- Calculate the total number of votes cast.
- Get a complete list of candidates who received votes.
- Calculate the total number of votes each candidate received.
- Calculate the percentage of votes each candidate won.
- Determine the winner of the election based on popular vote.
- Get a complete list of counties where votes were cast.
- Calculate the total number of votes cast in each county.
- Calculate the percentage of total votes for each county.
- Determine the county returning the largest number of votes in this election.
- Data Source: election_results.csv
- Software: Python 3.9.13, Visual Studio Code 1.72.2
The analyses of the election show that:
-
There were 369,711 votes cast in the election.
-
Congressional vote totals by county:
-
The candidates:
- Charles Casper Stockham
- Diana DeGette
- Raymon Anthony Doane
-
The candidate results:
- Charles Casper Stockham received 23.0% of the votes and 85,213 votes.
- Diana DeGette received 73.8% of the votes and 272,892 votes.
- Raymon Anthony Doane received 3.1% of the votes and 11,606 votes.
-
The winner of the election:
- Diana DeGette, who received 73.8% of the vote and 272,892 votes.
This audit of the results from mail-in ballots, punch cards, and DRE counting machines for a U.S. congressional precinct in Colorado was performed successfully with Python. This audit could have been completed using Excel, but by automating the process using Python, we are able to apply the Python script to audit other elections, including senatorial and local elections. The changes to the script for future election audits should include the following:
- Read the correct .csv input file for the district in line 9.
- Adjust the variables in line 51 from "county" to "district" or "state", as needed for areas of other elections being audited.
- Adjust the Election Results print out in line 88 to reflect geography (county, district, or state)