Skip to content

Instantly share code, notes, and snippets.

@NaimKabir
Created November 15, 2020 01:19
Show Gist options
  • Save NaimKabir/532b0f46630e8b3d8b28056c8d9dd70f to your computer and use it in GitHub Desktop.
Save NaimKabir/532b0f46630e8b3d8b28056c8d9dd70f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Performing Ayyadurai's Analysis, This Time On Democrats\n",
"\n",
"We'll do the same operations as Ayyadurai. We'll take fractions of the straight-ticket vote for Democrats, and fraction of votes for Biden among split-ticket voters to conduct our analysis.\n",
"\n",
"To get split-ticket voter percentages alone, we need to remove straight-ticket votes we know go towards candidates. This is to get as close to Ayyadurai's quantities as possible."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"split_ticket_data = presidential_vote_data.copy()\n",
"split_ticket_data[\"biden\"] -= straight_ticket_data[\"Democratic Party\"]\n",
"split_ticket_data[\"trump\"] -= straight_ticket_data[\"Republican Party\"]\n",
"split_ticket_data[\"jorgensen\"] -= straight_ticket_data[\"Libertarian Party\"]\n",
"split_ticket_data[\"blankenship\"] -= straight_ticket_data[\"U.S. Taxpayers Party\"]\n",
"split_ticket_data[\"hawkins\"] -= straight_ticket_data[\"Green Party\"]\n",
"split_ticket_data[\"rocky\"] -= straight_ticket_data[\"Natural Law Party\"]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# Get totals so we can frame our numbers as percentages\n",
"\n",
"straight_ticket_data[\"totals\"] = straight_ticket_data.sum(axis=1)\n",
"split_ticket_data[\"totals\"] = split_ticket_data.sum(axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# Get percentages\n",
"straight_ticket_data[\"%_democrat\"] = (\n",
" straight_ticket_data[\"Democratic Party\"] / straight_ticket_data[\"totals\"]\n",
")\n",
"split_ticket_data[\"%_biden\"] = (\n",
" split_ticket_data[\"biden\"] / split_ticket_data[\"totals\"]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can plot precinct percentages."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment