- Jun Seo Park
- Emma Duncan
The 2016 U.S. presidential election yielded an unexpected result for many - while an overwhelming majority of polls pointed to Hillary Clinton as the winner, Donald Trump eventually emerged the victor. In this project, we dive into the election poll data provided by FiveThirtyEight with the goal of visualizing the data to gain insight about polling accuracy leading up to the election.
- We used IPython notebooks to write our script, and the final product can be found on Election 2016.ipynb. More information about the two IPython notebooks can be found below.
- We have included both a .zip and .csv of the election poll data in the repository. If you wish to download or import the dataset using a link, it is available at http://projects.fivethirtyeight.com/general-model/president_general_polls_2016.csv.
There are two IPython notebooks in this repository: Election 2016.ipynb and Election 2016 (Bokeh).ipynb.
- Election 2016 is the main/current iteration, using the data visualization package Plotly. Plotly supports a variety of chart types, complete with detailed documentation for Python. If you are interested in porting the project into another language, Plotly also supports R, Matlab, and Excel, among others.
- Election 2016 (Bokeh) was the initial iteration, built upon the data visualization package Bokeh. Though Bokeh is a beautiful package with straightforward syntax, we ran into some major roadblocks with the lack of documentation and crucial missing features.
This project was built on virtual environments running Python 3.6 through Anaconda, and we have also included two separate requirements.txt files for Windows and OS X/macOS. To create a virtual environment, enter the following in a command-line interpreter (Anaconda Prompt, Terminal, etc.):
conda create python=3.6 --name [envname] --file [filepath]
- filepath refers to the path of the respective requirements.txt file.
To activate the environment on Windows:
activate [envname]
And on OS X/macOS:
source activate [envname]
Jupyter notebooks can be opened using the command:
jupyter notebook
And virtual environments can be closed by (preceded by source
on OS X/macOS):
deactivate [envname]
For more information regarding virtual environments, reference the official Conda documentation.
Plotly for Python requires an account and an API key, both of which are available on the free tier plan. Though the free tier plan is limited to 250 API calls per day, it offers access to the same amenities as paid tiers. Once an account has been made and an API key has been acquired, Plotly can be activated within the script using the code:
import plotly.plotly as py
py.sign_in('username', 'api_key')
For privacy reasons, we have executed then deleted this line from our Jupyter notebooks. Please follow these steps in order to recreate Plotly visualizations.