Skip to content

Commit 5f06747

Browse files
author
craigsdennis
committed
Adds third challenge.
1 parent 5c57a97 commit 5f06747

File tree

2 files changed

+399
-0
lines changed

2 files changed

+399
-0
lines changed
Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Optional Challenge - Verified Email List\n",
8+
"\n",
9+
"We want you to produce a new DataFrame that contains the only following columns:\n",
10+
"* first_name\n",
11+
"* last_name\n",
12+
"* email\n",
13+
"\n",
14+
"Ensure that all first names are title cased. Do not include any records that have a missing last name, and make sure that their email is verified (**`email_verified`** should be set True). Sort by last name and then by first.\n"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"# Setup\n",
24+
"import os\n",
25+
"\n",
26+
"import pandas as pd\n",
27+
"\n",
28+
"from utils import make_chaos\n",
29+
"\n",
30+
"from tests.helpers import check\n",
31+
"\n",
32+
"pd.options.display.max_rows = 10\n",
33+
"users = pd.read_csv(os.path.join('data', 'users.csv'), index_col=0)\n",
34+
"# Pay no attention to the person behind the curtain\n",
35+
"make_chaos(users, 19, ['first_name'], lambda val: val.lower())"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 2,
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/html": [
46+
"<div>\n",
47+
"<style scoped>\n",
48+
" .dataframe tbody tr th:only-of-type {\n",
49+
" vertical-align: middle;\n",
50+
" }\n",
51+
"\n",
52+
" .dataframe tbody tr th {\n",
53+
" vertical-align: top;\n",
54+
" }\n",
55+
"\n",
56+
" .dataframe thead th {\n",
57+
" text-align: right;\n",
58+
" }\n",
59+
"</style>\n",
60+
"<table border=\"1\" class=\"dataframe\">\n",
61+
" <thead>\n",
62+
" <tr style=\"text-align: right;\">\n",
63+
" <th></th>\n",
64+
" <th>first_name</th>\n",
65+
" <th>last_name</th>\n",
66+
" <th>email</th>\n",
67+
" <th>email_verified</th>\n",
68+
" <th>signup_date</th>\n",
69+
" <th>referral_count</th>\n",
70+
" <th>balance</th>\n",
71+
" </tr>\n",
72+
" </thead>\n",
73+
" <tbody>\n",
74+
" <tr>\n",
75+
" <th>aaron</th>\n",
76+
" <td>Aaron</td>\n",
77+
" <td>Davis</td>\n",
78+
" <td>aaron6348@gmail.com</td>\n",
79+
" <td>True</td>\n",
80+
" <td>2018-08-31</td>\n",
81+
" <td>6.0</td>\n",
82+
" <td>18.14</td>\n",
83+
" </tr>\n",
84+
" <tr>\n",
85+
" <th>acook</th>\n",
86+
" <td>Anthony</td>\n",
87+
" <td>Cook</td>\n",
88+
" <td>cook@gmail.com</td>\n",
89+
" <td>True</td>\n",
90+
" <td>2018-05-12</td>\n",
91+
" <td>2.0</td>\n",
92+
" <td>55.45</td>\n",
93+
" </tr>\n",
94+
" <tr>\n",
95+
" <th>adam.saunders</th>\n",
96+
" <td>Adam</td>\n",
97+
" <td>Saunders</td>\n",
98+
" <td>adam@gmail.com</td>\n",
99+
" <td>False</td>\n",
100+
" <td>2018-05-29</td>\n",
101+
" <td>3.0</td>\n",
102+
" <td>72.12</td>\n",
103+
" </tr>\n",
104+
" <tr>\n",
105+
" <th>adrian</th>\n",
106+
" <td>Adrian</td>\n",
107+
" <td>Yang</td>\n",
108+
" <td>adrian.yang@teamtreehouse.com</td>\n",
109+
" <td>True</td>\n",
110+
" <td>2018-04-28</td>\n",
111+
" <td>3.0</td>\n",
112+
" <td>30.01</td>\n",
113+
" </tr>\n",
114+
" <tr>\n",
115+
" <th>adrian.blair</th>\n",
116+
" <td>Adrian</td>\n",
117+
" <td>Blair</td>\n",
118+
" <td>adrian9335@gmail.com</td>\n",
119+
" <td>True</td>\n",
120+
" <td>2018-06-16</td>\n",
121+
" <td>7.0</td>\n",
122+
" <td>25.85</td>\n",
123+
" </tr>\n",
124+
" <tr>\n",
125+
" <th>...</th>\n",
126+
" <td>...</td>\n",
127+
" <td>...</td>\n",
128+
" <td>...</td>\n",
129+
" <td>...</td>\n",
130+
" <td>...</td>\n",
131+
" <td>...</td>\n",
132+
" <td>...</td>\n",
133+
" </tr>\n",
134+
" <tr>\n",
135+
" <th>wilson</th>\n",
136+
" <td>Robert</td>\n",
137+
" <td>Wilson</td>\n",
138+
" <td>robert@yahoo.com</td>\n",
139+
" <td>False</td>\n",
140+
" <td>2018-05-16</td>\n",
141+
" <td>5.0</td>\n",
142+
" <td>59.75</td>\n",
143+
" </tr>\n",
144+
" <tr>\n",
145+
" <th>wking</th>\n",
146+
" <td>Wanda</td>\n",
147+
" <td>King</td>\n",
148+
" <td>wanda.king@holt.com</td>\n",
149+
" <td>True</td>\n",
150+
" <td>2018-06-01</td>\n",
151+
" <td>2.0</td>\n",
152+
" <td>67.08</td>\n",
153+
" </tr>\n",
154+
" <tr>\n",
155+
" <th>wright3590</th>\n",
156+
" <td>Jacqueline</td>\n",
157+
" <td>Wright</td>\n",
158+
" <td>jacqueline.wright@gonzalez.com</td>\n",
159+
" <td>True</td>\n",
160+
" <td>2018-02-08</td>\n",
161+
" <td>6.0</td>\n",
162+
" <td>18.48</td>\n",
163+
" </tr>\n",
164+
" <tr>\n",
165+
" <th>young</th>\n",
166+
" <td>Jessica</td>\n",
167+
" <td>Young</td>\n",
168+
" <td>jessica4028@yahoo.com</td>\n",
169+
" <td>True</td>\n",
170+
" <td>2018-07-17</td>\n",
171+
" <td>4.0</td>\n",
172+
" <td>75.39</td>\n",
173+
" </tr>\n",
174+
" <tr>\n",
175+
" <th>zachary.neal</th>\n",
176+
" <td>Zachary</td>\n",
177+
" <td>Neal</td>\n",
178+
" <td>zneal@gmail.com</td>\n",
179+
" <td>True</td>\n",
180+
" <td>2018-07-26</td>\n",
181+
" <td>1.0</td>\n",
182+
" <td>39.90</td>\n",
183+
" </tr>\n",
184+
" </tbody>\n",
185+
"</table>\n",
186+
"<p>475 rows × 7 columns</p>\n",
187+
"</div>"
188+
],
189+
"text/plain": [
190+
" first_name last_name email \\\n",
191+
"aaron Aaron Davis aaron6348@gmail.com \n",
192+
"acook Anthony Cook cook@gmail.com \n",
193+
"adam.saunders Adam Saunders adam@gmail.com \n",
194+
"adrian Adrian Yang adrian.yang@teamtreehouse.com \n",
195+
"adrian.blair Adrian Blair adrian9335@gmail.com \n",
196+
"... ... ... ... \n",
197+
"wilson Robert Wilson robert@yahoo.com \n",
198+
"wking Wanda King wanda.king@holt.com \n",
199+
"wright3590 Jacqueline Wright jacqueline.wright@gonzalez.com \n",
200+
"young Jessica Young jessica4028@yahoo.com \n",
201+
"zachary.neal Zachary Neal zneal@gmail.com \n",
202+
"\n",
203+
" email_verified signup_date referral_count balance \n",
204+
"aaron True 2018-08-31 6.0 18.14 \n",
205+
"acook True 2018-05-12 2.0 55.45 \n",
206+
"adam.saunders False 2018-05-29 3.0 72.12 \n",
207+
"adrian True 2018-04-28 3.0 30.01 \n",
208+
"adrian.blair True 2018-06-16 7.0 25.85 \n",
209+
"... ... ... ... ... \n",
210+
"wilson False 2018-05-16 5.0 59.75 \n",
211+
"wking True 2018-06-01 2.0 67.08 \n",
212+
"wright3590 True 2018-02-08 6.0 18.48 \n",
213+
"young True 2018-07-17 4.0 75.39 \n",
214+
"zachary.neal True 2018-07-26 1.0 39.90 \n",
215+
"\n",
216+
"[475 rows x 7 columns]"
217+
]
218+
},
219+
"execution_count": 2,
220+
"metadata": {},
221+
"output_type": "execute_result"
222+
}
223+
],
224+
"source": [
225+
"## CHALLENGE - Verified email list ##\n",
226+
"\n",
227+
"# TODO: Narrow list to those that have email verified.\n",
228+
"# The only columns should be first, last and email\n",
229+
"email_list = users[:]\n",
230+
"\n",
231+
"# TODO: Remove any rows missing last names\n",
232+
"\n",
233+
"\n",
234+
"# TODO: Ensure that the first names are the proper case\n",
235+
"\n",
236+
"\n",
237+
"# Return the new sorted DataFrame\n",
238+
"email_list"
239+
]
240+
},
241+
{
242+
"cell_type": "code",
243+
"execution_count": 3,
244+
"metadata": {},
245+
"outputs": [
246+
{
247+
"data": {
248+
"text/markdown": [
249+
"```\n",
250+
"FFFFF\n",
251+
"======================================================================\n",
252+
"FAIL: test_columns (tests.helpers.TestVerifiedEmailList)\n",
253+
"----------------------------------------------------------------------\n",
254+
"Traceback (most recent call last):\n",
255+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 92, in test_columns\n",
256+
" ', '.join(expected.columns))\n",
257+
"AssertionError: 7 != 3 : Please only return the following columns: first_name, last_name, email\n",
258+
"\n",
259+
"======================================================================\n",
260+
"FAIL: test_email_verified (tests.helpers.TestVerifiedEmailList)\n",
261+
"----------------------------------------------------------------------\n",
262+
"Traceback (most recent call last):\n",
263+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 100, in test_email_verified\n",
264+
" \"Ensure that you are only including users with verified emails\"\n",
265+
"AssertionError: 475 != 358 : Ensure that you are only including users with verified emails\n",
266+
"\n",
267+
"======================================================================\n",
268+
"FAIL: test_has_na (tests.helpers.TestVerifiedEmailList)\n",
269+
"----------------------------------------------------------------------\n",
270+
"Traceback (most recent call last):\n",
271+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 83, in test_has_na\n",
272+
" \"Looks like there are still rows with last names missing. Drop them!\"\n",
273+
"AssertionError: 45 != 0 : Looks like there are still rows with last names missing. Drop them!\n",
274+
"\n",
275+
"======================================================================\n",
276+
"FAIL: test_sort (tests.helpers.TestVerifiedEmailList)\n",
277+
"----------------------------------------------------------------------\n",
278+
"Traceback (most recent call last):\n",
279+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 116, in test_sort\n",
280+
" msg\n",
281+
"AssertionError: 'Aaron' != 'Darlene'\n",
282+
"- Aaron\n",
283+
"+ Darlene\n",
284+
" : Check your sort, it should be last name and then first name\n",
285+
"\n",
286+
"======================================================================\n",
287+
"FAIL: test_title_cased (tests.helpers.TestVerifiedEmailList)\n",
288+
"----------------------------------------------------------------------\n",
289+
"Traceback (most recent call last):\n",
290+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 107, in test_title_cased\n",
291+
" \"Make sure you title case the first names, there are still some lower case versions\"\n",
292+
"AssertionError: 19 != 0 : Make sure you title case the first names, there are still some lower case versions\n",
293+
"\n",
294+
"----------------------------------------------------------------------\n",
295+
"Ran 5 tests in 0.030s\n",
296+
"\n",
297+
"FAILED (failures=5)\n",
298+
"\n",
299+
"```"
300+
],
301+
"text/plain": [
302+
"<IPython.core.display.Markdown object>"
303+
]
304+
},
305+
"metadata": {},
306+
"output_type": "display_data"
307+
}
308+
],
309+
"source": [
310+
"check(__name__, 'Verified email list')"
311+
]
312+
}
313+
],
314+
"metadata": {
315+
"kernelspec": {
316+
"display_name": "Python 3",
317+
"language": "python",
318+
"name": "python3"
319+
},
320+
"language_info": {
321+
"codemirror_mode": {
322+
"name": "ipython",
323+
"version": 3
324+
},
325+
"file_extension": ".py",
326+
"mimetype": "text/x-python",
327+
"name": "python",
328+
"nbconvert_exporter": "python",
329+
"pygments_lexer": "ipython3",
330+
"version": "3.7.0"
331+
}
332+
},
333+
"nbformat": 4,
334+
"nbformat_minor": 2
335+
}

0 commit comments

Comments
 (0)