{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Optional Challenge 1 - Top Referrers\n", "\n", "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. \n", "\n", "Currently, anyone with **5 or more** referrals is considered a top referrer.\n", "\n", "When you have completed the challenge, press the `Run Tests` button.\n", "\n", "*Need a little extra help? Check out the [Treehouse Forum](https://teamtreehouse.com/community?instruction=4552).*" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "475" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Setup\n", "import os\n", "import pandas as pd\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", "# Pop out a quick sanity check\n", "len(users)" ] }, { "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-31618.14
acookAnthonyCookcook@gmail.comTrue2018-05-12255.45
adam.saundersAdamSaundersadam@gmail.comFalse2018-05-29372.12
adrianAdrianFangadrian.fang@teamtreehouse.comTrue2018-04-28330.01
adrian.blairAdrianBlairadrian9335@gmail.comTrue2018-06-16725.85
........................
wilsonRobertWilsonrobert@yahoo.comFalse2018-05-16559.75
wkingWandaKingwanda.king@holt.comTrue2018-06-01267.08
wright3590JacquelineWrightjacqueline.wright@gonzalez.comTrue2018-02-08618.48
youngJessicaYoungjessica4028@yahoo.comTrue2018-07-17475.39
zachary.nealZacharyNealzneal@gmail.comTrue2018-07-26139.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 Fang adrian.fang@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 18.14 \n", "acook True 2018-05-12 2 55.45 \n", "adam.saunders False 2018-05-29 3 72.12 \n", "adrian True 2018-04-28 3 30.01 \n", "adrian.blair True 2018-06-16 7 25.85 \n", "... ... ... ... ... \n", "wilson False 2018-05-16 5 59.75 \n", "wking True 2018-06-01 2 67.08 \n", "wright3590 True 2018-02-08 6 18.48 \n", "young True 2018-07-17 4 75.39 \n", "zachary.neal True 2018-07-26 1 39.90 \n", "\n", "[475 rows x 7 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## CHALLENGE - Find the top referrers ##\n", "# TODO: Select users that have a referral count greater than or equal to 5 and have verified emails\n", "\n", "# Return the dataframe\n", "users" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3173395f5f7e4c1dacc395df45c550f1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='Run Tests', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "```\n", "FFF\n", "======================================================================\n", "FAIL: test_email_verified (tests.helpers.TestReferralCounts)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 26, in test_email_verified\n", " \"I found some emails that weren't verified, are you sure you limited it by verified only?\")\n", "AssertionError: 0 != 86 : I found some emails that weren't verified, are you sure you limited it by verified only?\n", "\n", "======================================================================\n", "FAIL: test_referral_counts (tests.helpers.TestReferralCounts)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 31, in test_referral_counts\n", " \"I found some referral counts that were less than 5. Check your condition.\")\n", "AssertionError: 0 != 300 : I found some referral counts that were less than 5. Check your condition.\n", "\n", "======================================================================\n", "FAIL: test_total (tests.helpers.TestReferralCounts)\n", "----------------------------------------------------------------------\n", "Traceback (most recent call last):\n", " File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 35, in test_total\n", " \"Whoops I received a different count than I expected, make sure the last line \"\n", "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)\n", "\n", "----------------------------------------------------------------------\n", "Ran 3 tests in 0.006s\n", "\n", "FAILED (failures=3)\n", "\n", "```" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "check(__name__, 'Find the top referrers')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }