Optional Challenge 1 - Top Referrers

We at CashBox believe that referrers are a great asset to our product. We'd like to know the top referrers with verified email addresses, so that we can send them some motivational emails.

Currently, anyone with 5 or more referrals is considered a top referrer.

When you have completed the challenge, press the Run Tests button.

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

In [1]:
# Setup
import os
import pandas as pd

from tests.helpers import check

pd.options.display.max_rows = 10
users = pd.read_csv(os.path.join('data', 'users.csv'), index_col=0)
# Pop out a quick sanity check
len(users)
Out[1]:
475
In [2]:
## CHALLENGE - Find the top referrers ##
# TODO: Select users that have a referral count greater than or equal to 5 and have verified emails

# Return the dataframe
users
Out[2]:
first_name last_name email email_verified signup_date referral_count balance
aaron Aaron Davis [email protected] True 2018-08-31 6 18.14
acook Anthony Cook [email protected] True 2018-05-12 2 55.45
adam.saunders Adam Saunders [email protected] False 2018-05-29 3 72.12
adrian Adrian Fang [email protected] True 2018-04-28 3 30.01
adrian.blair Adrian Blair [email protected] True 2018-06-16 7 25.85
... ... ... ... ... ... ... ...
wilson Robert Wilson [email protected] False 2018-05-16 5 59.75
wking Wanda King [email protected] True 2018-06-01 2 67.08
wright3590 Jacqueline Wright [email protected] True 2018-02-08 6 18.48
young Jessica Young [email protected] True 2018-07-17 4 75.39
zachary.neal Zachary Neal [email protected] True 2018-07-26 1 39.90

475 rows × 7 columns

In [3]:
check(__name__, 'Find the top referrers')
FFF
======================================================================
FAIL: test_email_verified (tests.helpers.TestReferralCounts)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 26, in test_email_verified
    "I found some emails that weren't verified, are you sure you limited it by verified only?")
AssertionError: 0 != 86 : I found some emails that weren't verified, are you sure you limited it by verified only?

======================================================================
FAIL: test_referral_counts (tests.helpers.TestReferralCounts)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 31, in test_referral_counts
    "I found some referral counts that were less than 5. Check your condition.")
AssertionError: 0 != 300 : I found some referral counts that were less than 5. Check your condition.

======================================================================
FAIL: test_total (tests.helpers.TestReferralCounts)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py", line 35, in test_total
    "Whoops I received a different count than I expected, make sure the last line "
AssertionError: 475 != 142 : Whoops I received a different count than I expected, make sure the last line is the entire resulting DataFrame (not just the head)

----------------------------------------------------------------------
Ran 3 tests in 0.006s

FAILED (failures=3)
In [ ]: