Optional Challenge - Verified Email List

We want you to produce a new DataFrame that contains the only following columns:

  • first_name
  • last_name
  • email

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.

Once you have completed the TODOs, choose the Run Tests button.

Need a little extra help? Check out the Treehouse Forum.

In [1]:
# Setup
import os

import pandas as pd

from utils import make_chaos

from tests.helpers import check

pd.options.display.max_rows = 10
users = pd.read_csv(os.path.join('data', 'users.csv'), index_col=0)
# Pay no attention to the person behind the curtain
make_chaos(users, 19, ['first_name'], lambda val: val.lower())
In [2]:
## CHALLENGE - Verified email list ##

# TODO: Narrow list to those that have email verified.
#  The only columns should be first, last and email
email_list = users[:]

# TODO: Remove any rows missing last names


# TODO: Ensure that the first names are the proper case


# Return the new sorted DataFrame..last name then first name ascending
email_list
Out[2]:
first_name last_name email email_verified signup_date referral_count balance
aaron Aaron Davis [email protected] True 2018-08-31 6.0 18.14
acook Anthony Cook [email protected] True 2018-05-12 2.0 55.45
adam.saunders Adam Saunders [email protected] False 2018-05-29 3.0 72.12
adrian Adrian Fang [email protected]se.com True 2018-04-28 3.0 30.01
adrian.blair Adrian Blair [email protected] True 2018-06-16 7.0 25.85
... ... ... ... ... ... ... ...
wilson Robert Wilson [email protected] False 2018-05-16 5.0 59.75
wking Wanda King [email protected] True 2018-06-01 2.0 67.08
wright3590 Jacqueline Wright [email protected] True 2018-02-08 6.0 18.48
young Jessica Young [email protected] True 2018-07-17 4.0 75.39
zachary.neal Zachary Neal [email protected] True 2018-07-26 1.0 39.90

475 rows × 7 columns

In [3]:
check(__name__, 'Verified email list')
FFFFF
======================================================================
FAIL: test_columns (tests.helpers.TestVerifiedEmailList)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 92, in test_columns
    ', '.join(expected.columns))
AssertionError: 7 != 3 : Please only return the following columns: first_name, last_name, email

======================================================================
FAIL: test_email_verified (tests.helpers.TestVerifiedEmailList)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 100, in test_email_verified
    "Ensure that you are only including users with verified emails"
AssertionError: 475 != 358 : Ensure that you are only including users with verified emails

======================================================================
FAIL: test_has_na (tests.helpers.TestVerifiedEmailList)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 83, in test_has_na
    "Looks like there are still rows with last names missing. Drop them!"
AssertionError: 45 != 0 : Looks like there are still rows with last names missing. Drop them!

======================================================================
FAIL: test_sort (tests.helpers.TestVerifiedEmailList)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 116, in test_sort
    msg
AssertionError: 'Aaron' != 'Darlene'
- Aaron
+ Darlene
 : Check your sort, it should be last name and then first name

======================================================================
FAIL: test_title_cased (tests.helpers.TestVerifiedEmailList)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 107, in test_title_cased
    "Make sure you title case the first names, there are still some lower case versions"
AssertionError: 19 != 0 : Make sure you title case the first names, there are still some lower case versions

----------------------------------------------------------------------
Ran 5 tests in 0.033s

FAILED (failures=5)