Lecture 19 – Exploratory Data Analysis: Voter Targeting in Pennsylvania

Data 6, Summer 2021

Run the next cell to import all of our datasets, obtained from https://www.electionreturns.pa.gov/ and https://www.truckads.com/.

Step 1: Data Cleaning

To make this easier, let's cut it down to the columns we want. (For this section, don't re-run cells! You'll get an error.)

Step 2: Exploratory Data Analysis

Our questions for this analysis:

Let's learn more about where voters voted and how they voted. We're going to use group and pivot for this.

Recall: tbl.group("col", func) If func is not specified, by default finds the count of each unique value in "col". Otherwise, applies func to the grouped values in every other column.

tbl.pivot("col", "row", "vals", func) cross-classifies a dataset, making all the unique values in 1 column the new rows and all the unique values in the other column the new column labels. Then, it puts the values of "vals", with the function applied to each group, in the corresponding cells.

For example: http://data8.org/interactive_table_functions/