Coder Social home page Coder Social logo

election_analysis's Introduction

Election Analysis

Overview of Election Audit

A Colorado Board of Elections employee requested an election audit for a recent local congressional election. Ballot data including Ballot #, County and Candidate was supplied in a .csv file.

The required deliverables are given as:

  1. Total number of votes cast
  2. Total number and percentage of votes cast by county
  3. The county with the highest voter turnout
  4. Total number and percentage of votes cast for each Candidate
  5. The winner of the election based on popular vote

Resources

Election Audit Results

Election Outcomes

  • Total number of votes cast: 369,711
  • Percentage and total number of votes cast by county:
    • Jefferson: 10.5% (38,855 total votes)
    • Denver: 82.8% (306,055 total votes) *highest voter turnout*
    • Arapahoe: 6.7% (24,801 total votes)
  • Percentage and total number of votes cast by candidate:
    • Charles Casper Stockham: 23.0% (85,213 total votes)
    • Diana DeGette: 73.8% (272,892 total votes) *winner based on popular vote*
    • Raymon Anthony Doane: 3.1% (11,606 total votes)

Python Code: PyPoll_Challenge.py

  • The completed python script is available here
  • Results were also printed to election_analysis.txt
  • Running PyPoll_Challenge.py script in VS Code gives the following terminal output: image PyPoll terminal

Election Audit Summary

The winner of this election, according to popular vote, is Diana DeGette with 73.8% over the vote (272,892 total votes). The county with largest election turnout (82.8% of the total ballots and 306,055 of the total votes) is Denver county.

Future Use

This script is dynamic enough exactly as it is to support re-use for any election audit of the same type - a unique ballot id, multiple county names and mutiple candidate names - when the required deliverables are the same. The name and path of the .csv file_to_load should be updated, and a new name and path to the file_to_save should also be specified. The output will be in the same format. The supplied .csv file can contain any number of county names and candidates.

More broadly, it can also support an analysis where instead of candidate names, any set of ballot initiatives or measures are listed in that column instead.

Similarly to County Votes, another demographic variable associated with the ballot could be explored and added to the code in another set of for loops. For example, if the party affiliation of the voter is available, the script could be expanded by initializing a counter for party_vote. Subsequent code blocks for this new varible would be added under each section just as the county blocks are setup. Another if statement in the for row in reader: loop will extract and manipulate the party data. To print the additional output, an added for loop in front of the section for county_name in county_votes: would render the party percentages and turnout.

election_analysis's People

Contributors

lnshewmo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.