{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Optional Challenge - Verified Email List\n", "\n", "We want you to produce a new DataFrame that contains the only following columns:\n", "* first_name\n", "* last_name\n", "* email\n", "\n", "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", "\n", "Choose `Kernel > Restart & Run all` to run the tests properly. \n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Setup\n", "import os\n", "\n", "import pandas as pd\n", "\n", "from utils import make_chaos\n", "\n", "from tests.helpers import check\n", "\n", "pd.options.display.max_rows = 10\n", "users = pd.read_csv(os.path.join('data', 'users.csv'), index_col=0)\n", "# Pay no attention to the person behind the curtain\n", "make_chaos(users, 19, ['first_name'], lambda val: val.lower())" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
first_namelast_nameemailemail_verifiedsignup_datereferral_countbalance
aaronAaronDavisaaron6348@gmail.comTrue2018-08-316.018.14
acookAnthonyCookcook@gmail.comTrue2018-05-122.055.45
adam.saundersAdamSaundersadam@gmail.comFalse2018-05-293.072.12
adrianAdrianYangadrian.yang@teamtreehouse.comTrue2018-04-283.030.01
adrian.blairAdrianBlairadrian9335@gmail.comTrue2018-06-167.025.85
........................
wilsonRobertWilsonrobert@yahoo.comFalse2018-05-165.059.75
wkingWandaKingwanda.king@holt.comTrue2018-06-012.067.08
wright3590JacquelineWrightjacqueline.wright@gonzalez.comTrue2018-02-086.018.48
youngJessicaYoungjessica4028@yahoo.comTrue2018-07-174.075.39
zachary.nealZacharyNealzneal@gmail.comTrue2018-07-261.039.90
\n", "

475 rows × 7 columns

\n", "
" ], "text/plain": [ " first_name last_name email \\\n", "aaron Aaron Davis aaron6348@gmail.com \n", "acook Anthony Cook cook@gmail.com \n", "adam.saunders Adam Saunders adam@gmail.com \n", "adrian Adrian Yang adrian.yang@teamtreehouse.com \n", "adrian.blair Adrian Blair adrian9335@gmail.com \n", "... ... ... ... \n", "wilson Robert Wilson robert@yahoo.com \n", "wking Wanda King wanda.king@holt.com \n", "wright3590 Jacqueline Wright jacqueline.wright@gonzalez.com \n", "young Jessica Young jessica4028@yahoo.com \n", "zachary.neal Zachary Neal zneal@gmail.com \n", "\n", " email_verified signup_date referral_count balance \n", "aaron True 2018-08-31 6.0 18.14 \n", "acook True 2018-05-12 2.0 55.45 \n", "adam.saunders False 2018-05-29 3.0 72.12 \n", "adrian True 2018-04-28 3.0 30.01 \n", "adrian.blair True 2018-06-16 7.0 25.85 \n", "... ... ... ... ... \n", "wilson False 2018-05-16 5.0 59.75 \n", "wking True 2018-06-01 2.0 67.08 \n", "wright3590 True 2018-02-08 6.0 18.48 \n", "young True 2018-07-17 4.0 75.39 \n", "zachary.neal True 2018-07-26 1.0 39.90 \n", "\n", "[475 rows x 7 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## CHALLENGE - Verified email list ##\n", "\n", "# TODO: Narrow list to those that have email verified.\n", "# The only columns should be first, last and email\n", "email_list = users[:]\n", "\n", "# TODO: Remove any rows missing last names\n", "\n", "\n", "# TODO: Ensure that the first names are the proper case\n", "\n", "\n", "# Return the new sorted DataFrame..last name then first name ascending\n", "email_list" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "```\n", "FFFFF\n", "======================================================================\n", "FAIL: test_columns (tests.helpers.TestVerifiedEmailList)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 92, in test_columns\n", " ', '.join(expected.columns))\n", "AssertionError: 7 != 3 : Please only return the following columns: first_name, last_name, email\n", "\n", "======================================================================\n", "FAIL: test_email_verified (tests.helpers.TestVerifiedEmailList)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 100, in test_email_verified\n", " \"Ensure that you are only including users with verified emails\"\n", "AssertionError: 475 != 358 : Ensure that you are only including users with verified emails\n", "\n", "======================================================================\n", "FAIL: test_has_na (tests.helpers.TestVerifiedEmailList)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 83, in test_has_na\n", " \"Looks like there are still rows with last names missing. Drop them!\"\n", "AssertionError: 45 != 0 : Looks like there are still rows with last names missing. Drop them!\n", "\n", "======================================================================\n", "FAIL: test_sort (tests.helpers.TestVerifiedEmailList)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 116, in test_sort\n", " msg\n", "AssertionError: 'Aaron' != 'Darlene'\n", "- Aaron\n", "+ Darlene\n", " : Check your sort, it should be last name and then first name\n", "\n", "======================================================================\n", "FAIL: test_title_cased (tests.helpers.TestVerifiedEmailList)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 107, in test_title_cased\n", " \"Make sure you title case the first names, there are still some lower case versions\"\n", "AssertionError: 19 != 0 : Make sure you title case the first names, there are still some lower case versions\n", "\n", "----------------------------------------------------------------------\n", "Ran 5 tests in 0.030s\n", "\n", "FAILED (failures=5)\n", "\n", "```" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "check(__name__, 'Verified email list')" ] } ], "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.0" } }, "nbformat": 4, "nbformat_minor": 2 }