Skip to content

Commit a2a177f

Browse files
authored
Add files via upload
0 parents  commit a2a177f

2 files changed

+620
-0
lines changed

Hackforge_Demo_Election_Results.ipynb

+290
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Hackforge - Intro to Python for Data Exploration\n",
8+
"With opendata.citywindsor.ca\n",
9+
"\n",
10+
"December 2021"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"# Some Python Basics we'll use during this talk"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"c = 3\n",
29+
"d = 7.9\n",
30+
"e = \"2018 Windsor Election Results\"\n",
31+
"f = True\n",
32+
"g = 2021-12-31"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"# What are the datatypes of our variables?\n",
42+
"type(g)"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"# Importing Python Libraries\n",
52+
"# Install your libraries using Anaconda\n",
53+
"\n",
54+
"import datetime\n",
55+
"\n",
56+
"g = datetime.datetime(2021, 12, 31)\n"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"print(g)"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"## Who won Windor's 2018 Election for Mayor?"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"![title](https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Pandas_logo.svg/450px-Pandas_logo.svg.png)"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"## Load and Explore the Election Data"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": null,
92+
"metadata": {},
93+
"outputs": [],
94+
"source": [
95+
"# Load Pandas libraries\n",
96+
"\n",
97+
"import pandas as pd"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"dataframe = pd.read_csv(\"https://opendata.citywindsor.ca/Uploads/detailedresults-2018.csv\", encoding='unicode_escape')\n",
107+
"\n",
108+
"\n",
109+
"# dataframe = pd.read_excel(\"https://opendata.citywindsor.ca/Uploads/Election2014.xlsx\", encoding='unicode_escape')"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": null,
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"# What type is our variable named dataframe?\n",
119+
"\n"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": null,
125+
"metadata": {},
126+
"outputs": [],
127+
"source": [
128+
"# How many records and attributes did we load?\n",
129+
"\n",
130+
"dataframe."
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": null,
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"# What types of data did Python auto-detect?\n",
140+
"dataframe.dtypes"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": null,
146+
"metadata": {},
147+
"outputs": [],
148+
"source": [
149+
"# What does the top and bottom of my tabular DataFrame look like?\n",
150+
"\n",
151+
"dataframe."
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": [
160+
"# Or, use Slicing\n",
161+
"\n",
162+
"dataframe"
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": null,
168+
"metadata": {},
169+
"outputs": [],
170+
"source": [
171+
"dataframe[\"Contest Title\"].value_counts()"
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": null,
177+
"metadata": {},
178+
"outputs": [],
179+
"source": [
180+
"# selecting rows based on condition\n",
181+
"\n",
182+
"df = dataframe[dataframe['Contest Title'] == 'MAYOR']"
183+
]
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": null,
188+
"metadata": {},
189+
"outputs": [],
190+
"source": [
191+
"df[560:565]"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": null,
197+
"metadata": {},
198+
"outputs": [],
199+
"source": [
200+
"df.shape\n"
201+
]
202+
},
203+
{
204+
"cell_type": "code",
205+
"execution_count": null,
206+
"metadata": {},
207+
"outputs": [],
208+
"source": [
209+
"# Who are the canidates?\n",
210+
"pd.unique(df['Candidate Name'])"
211+
]
212+
},
213+
{
214+
"cell_type": "code",
215+
"execution_count": null,
216+
"metadata": {},
217+
"outputs": [],
218+
"source": [
219+
"# Group the canidates and their votes together\n",
220+
"total_votes = df.groupby([\"Candidate Name\"])[\"Total\"].sum().sort_values(ascending = False)"
221+
]
222+
},
223+
{
224+
"cell_type": "code",
225+
"execution_count": null,
226+
"metadata": {},
227+
"outputs": [],
228+
"source": [
229+
"total_votes"
230+
]
231+
},
232+
{
233+
"cell_type": "code",
234+
"execution_count": null,
235+
"metadata": {},
236+
"outputs": [],
237+
"source": [
238+
"# Use Markdown to Create a Heading Two Section Title"
239+
]
240+
},
241+
{
242+
"cell_type": "code",
243+
"execution_count": null,
244+
"metadata": {},
245+
"outputs": [],
246+
"source": [
247+
"import matplotlib.pyplot as plt"
248+
]
249+
},
250+
{
251+
"cell_type": "code",
252+
"execution_count": null,
253+
"metadata": {},
254+
"outputs": [],
255+
"source": [
256+
"total_votes.plot.bar()\n",
257+
"plt.ylabel('Total Votes')\n",
258+
"plt.title(e)\n"
259+
]
260+
},
261+
{
262+
"cell_type": "code",
263+
"execution_count": null,
264+
"metadata": {},
265+
"outputs": [],
266+
"source": []
267+
}
268+
],
269+
"metadata": {
270+
"kernelspec": {
271+
"display_name": "Python 3",
272+
"language": "python",
273+
"name": "python3"
274+
},
275+
"language_info": {
276+
"codemirror_mode": {
277+
"name": "ipython",
278+
"version": 3
279+
},
280+
"file_extension": ".py",
281+
"mimetype": "text/x-python",
282+
"name": "python",
283+
"nbconvert_exporter": "python",
284+
"pygments_lexer": "ipython3",
285+
"version": "3.7.4"
286+
}
287+
},
288+
"nbformat": 4,
289+
"nbformat_minor": 2
290+
}

Hackforge_Demo_Traffic.ipynb

+330
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)