showkatewang / Election_Analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Election_Analysis

Overview

The purpose of this audit is to read a simulated election results from csv file, analyze data with a separate py file, then write the results of analysis to a txt file. Project objectives include calculations of

  1. Total vote count
  2. Number and percentage of votes per county
  3. County with the largest turnout
  4. Number and percentage of votes percandidate
  5. Winning candidate based on popular vote

Resources

Data source: election_results.csv

Software: Python 3.9.7, Visual Studio Code (VSCode) 1.63.2

Results

  • A total of 369,711 votes were cast for the election.
  • The counties
    • Jefferson county
    • Denver county
    • Arapahoe county
  • The county results
    • Jefferson county cast roughly 10.5% of the vote and 38,855 of votes;
    • Denver county cast roughly 82.8% of the vote and 306,055 of votes;
    • Arapahoe county cast roughly 6.7% of the vote and 24,801 of votes.
  • The largest turnout of the election
    • Denver county that cast 82.8% of the vote and 306,055 of votes.
  • The candidates
    • Charles Casper Stockham
    • Diana DeGette
    • Raymon Anthony Doane
  • The candidate results
    • Charles Casper Stockham received about 23.0% of the votes and 85,213 of votes;
    • Diana DeGette received about 73.8% of the vote and 272,892 of votes;
    • Raymon Anthony Doane received about 3.1% of the vote and 11,606 of votes.
  • The winner of this election
    • Diana DeGette, who received 73.8% of the vote and 272,892 of votes.

Initialized variables are shown below. election_analysis_initialize_variables

File opened and analysis calculations are shown below. election_analysis_read_to_file

Write-to file and result calculations are shown below. election_analysis_write_to_file

Analysis results are shown below. election_analysis_output

Summary

With some modifications, codes for this election may be adapted for any election. One such modification is to use Jupyter Lab/Notebook to confirm calculations are executed smoothly with every line of code. Another modification is to streamline the script by reading the file only once to effectuate all ouputs. Notice calculations and printing for counties are similar to that of the candidates, implying that the script can be simplified with either built-in functions, constructed generators, or list comprehensions. More efficient codes take up less memory space. Lastly, the variables may benefit from re-naming to maintain readability and ensure style consistency.

About


Languages

Language:Python 100.0%