# 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:

• How did each party vote? Remember that the GOP was very against mail-in-ballots in 2020.

• What media markets supported each party in 2020? Pennsylvania is going through a demographic and economic shift, so this may have insights for 2022 or 2024.

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/