A Colorado Board of Elections employee has given you 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.
- Get a complete list of the counties where people voted in this election.
- Calculate the total number of votes each candidate received.
- Calculate the total number of votes that were casted in each county.
- Calculate the percentage of votes each candidate won.
- Calculate the percentage of votes of each county.
- Determine the winner of the election based on popular vote.
- Determine the county with the most votes casted.
- Data Source: election_results.csv
- Software: Python 3.7.6, Visual Studio Code, 1.54.1
The analysis of the election show that:
-
There were 369,711 votes cast in the election.
-
The candidates were:
- Charles Casper Stockham
- Diana DeGette
- Raymon Anthony Doane
-
The counties that participated in this election were:
- Jefferson
- Arapahoe
- Denver
-
The county with the most votes was:
- Denver County which had 82.8% of the votes relative to the total votes casted in this election.
- Denver County received 306,055 votes in total.
-
The candidate results were:
- Charles Casper Stockham received 23.0% of the vote and 85,213 number of votes.
- Diana DeGette received 73.8% of the vote and 272,892 number of votes.
- Raymon Anthony Doane received 3.1% of the vote and 11,606 number of votes.
-
The winner of the election was:
- Diana DeGette received 73.8% of the vote and 272,892 number of votes.
- The winner of the recent local congressional election in Colorado was Diana Degette who received 73.8% of the vote. The county where the most votes were casted was Denver.
- The script written to determine the total votes, the votes for each candidate, the percentage of votes for each candidate, the candidate winner, the votes casted in each county, the percentage of votes casted in each county, and the county with the most votes can be reused again for another election if the .csv file of the data for that election was formatted the same as the election_results.csv file that was used for the script (seem image above for reference).
-
One way to reuse this script for another election is if the ballot ID, county, and candidate columns are in a different order for another election data to be analyzed, be sure that the index number placed for these variables match the column in which you want the data from so that the same code can be reused.
-
Likewise, the second way to reuse this script could be for a presidential election. However, in order to declare which state a candidate won, there would have to be both an analysis of who won which county and then an additional analysis to sum up which candidate won the majority of the vote in that state in order to reflect the complexity of the electoral college.
-
Overall, this script can be reapplied to many different election scenarioes such as a school student body president election (in this case, the code pertaining to information about the counties is unnecessary) or a presidential election in which more code would needed to be added in order to account for how the electoral college operates.


