{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "\n", " \n", "___\n", "# Ecommerce Purchases Exercise\n", "\n", "In this Exercise you will be given some Fake Data about some purchases done through Amazon! Just go ahead and follow the directions and try your best to answer the questions and complete the tasks. Feel free to reference the solutions. Most of the tasks can be solved in different ways. For the most part, the questions get progressively harder.\n", "\n", "Please excuse anything that doesn't make \"Real-World\" sense in the dataframe, all the data is fake and made-up.\n", "\n", "Also note that all of these questions can be answered with one line of code.\n", "____\n", "** Import pandas and read in the Ecommerce Purchases csv file and set it to a DataFrame called ecom. **" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 86, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Check the head of the DataFrame.**" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": false }, "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", "
AddressLotAM or PMBrowser InfoCompanyCredit CardCC Exp DateCC Security CodeCC ProviderEmailJobIP AddressLanguagePurchase Price
016629 Pace Camp Apt. 448\\nAlexisborough, NE 77...46 inPMOpera/9.56.(X11; Linux x86_64; sl-SI) Presto/2...Martinez-Herman601192906112340602/20900JCB 16 digitpdunlap@yahoo.comScientist, product/process development149.146.147.205el98.14
19374 Jasmine Spurs Suite 508\\nSouth John, TN 8...28 rnPMOpera/8.93.(Windows 98; Win 9x 4.90; en-US) Pr...Fletcher, Richards and Whitaker333775816964535611/18561Mastercardanthony41@reed.comDrilling engineer15.160.41.51fr70.73
2Unit 0065 Box 5052\\nDPO AP 2745094 vEPMMozilla/5.0 (compatible; MSIE 9.0; Windows NT ...Simpson, Williams and Pham67595766612508/19699JCB 16 digitamymiller@morales-harrison.comCustomer service manager132.207.160.22de0.95
37780 Julia Fords\\nNew Stacy, WA 4579836 vmPMMozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0 ...Williams, Marshall and Buchanan601157850443071002/24384Discoverbrent16@olson-robinson.infoDrilling engineer30.250.74.19es78.04
423012 Munoz Drive Suite 337\\nNew Cynthia, TX 5...20 IEAMOpera/9.58.(X11; Linux x86_64; it-IT) Presto/2...Brown, Watson and Andrews601145662320799810/25678Diners Club / Carte Blanchechristopherwright@gmail.comFine artist24.140.33.94es77.82
\n", "
" ], "text/plain": [ " Address Lot AM or PM \\\n", "0 16629 Pace Camp Apt. 448\\nAlexisborough, NE 77... 46 in PM \n", "1 9374 Jasmine Spurs Suite 508\\nSouth John, TN 8... 28 rn PM \n", "2 Unit 0065 Box 5052\\nDPO AP 27450 94 vE PM \n", "3 7780 Julia Fords\\nNew Stacy, WA 45798 36 vm PM \n", "4 23012 Munoz Drive Suite 337\\nNew Cynthia, TX 5... 20 IE AM \n", "\n", " Browser Info \\\n", "0 Opera/9.56.(X11; Linux x86_64; sl-SI) Presto/2... \n", "1 Opera/8.93.(Windows 98; Win 9x 4.90; en-US) Pr... \n", "2 Mozilla/5.0 (compatible; MSIE 9.0; Windows NT ... \n", "3 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0 ... \n", "4 Opera/9.58.(X11; Linux x86_64; it-IT) Presto/2... \n", "\n", " Company Credit Card CC Exp Date \\\n", "0 Martinez-Herman 6011929061123406 02/20 \n", "1 Fletcher, Richards and Whitaker 3337758169645356 11/18 \n", "2 Simpson, Williams and Pham 675957666125 08/19 \n", "3 Williams, Marshall and Buchanan 6011578504430710 02/24 \n", "4 Brown, Watson and Andrews 6011456623207998 10/25 \n", "\n", " CC Security Code CC Provider \\\n", "0 900 JCB 16 digit \n", "1 561 Mastercard \n", "2 699 JCB 16 digit \n", "3 384 Discover \n", "4 678 Diners Club / Carte Blanche \n", "\n", " Email Job \\\n", "0 pdunlap@yahoo.com Scientist, product/process development \n", "1 anthony41@reed.com Drilling engineer \n", "2 amymiller@morales-harrison.com Customer service manager \n", "3 brent16@olson-robinson.info Drilling engineer \n", "4 christopherwright@gmail.com Fine artist \n", "\n", " IP Address Language Purchase Price \n", "0 149.146.147.205 el 98.14 \n", "1 15.160.41.51 fr 70.73 \n", "2 132.207.160.22 de 0.95 \n", "3 30.250.74.19 es 78.04 \n", "4 24.140.33.94 es 77.82 " ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** How many rows and columns are there? **" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 10000 entries, 0 to 9999\n", "Data columns (total 14 columns):\n", "Address 10000 non-null object\n", "Lot 10000 non-null object\n", "AM or PM 10000 non-null object\n", "Browser Info 10000 non-null object\n", "Company 10000 non-null object\n", "Credit Card 10000 non-null int64\n", "CC Exp Date 10000 non-null object\n", "CC Security Code 10000 non-null int64\n", "CC Provider 10000 non-null object\n", "Email 10000 non-null object\n", "Job 10000 non-null object\n", "IP Address 10000 non-null object\n", "Language 10000 non-null object\n", "Purchase Price 10000 non-null float64\n", "dtypes: float64(1), int64(2), object(11)\n", "memory usage: 1.1+ MB\n" ] } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** What is the average Purchase Price? **" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "50.34730200000025" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** What were the highest and lowest purchase prices? **" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "99.989999999999995" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** How many people have English 'en' as their Language of choice on the website? **" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Address 1098\n", "Lot 1098\n", "AM or PM 1098\n", "Browser Info 1098\n", "Company 1098\n", "Credit Card 1098\n", "CC Exp Date 1098\n", "CC Security Code 1098\n", "CC Provider 1098\n", "Email 1098\n", "Job 1098\n", "IP Address 1098\n", "Language 1098\n", "Purchase Price 1098\n", "dtype: int64" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** How many people have the job title of \"Lawyer\" ? **\n" ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Int64Index: 30 entries, 470 to 9979\n", "Data columns (total 14 columns):\n", "Address 30 non-null object\n", "Lot 30 non-null object\n", "AM or PM 30 non-null object\n", "Browser Info 30 non-null object\n", "Company 30 non-null object\n", "Credit Card 30 non-null int64\n", "CC Exp Date 30 non-null object\n", "CC Security Code 30 non-null int64\n", "CC Provider 30 non-null object\n", "Email 30 non-null object\n", "Job 30 non-null object\n", "IP Address 30 non-null object\n", "Language 30 non-null object\n", "Purchase Price 30 non-null float64\n", "dtypes: float64(1), int64(2), object(11)\n", "memory usage: 3.5+ KB\n" ] } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** How many people made the purchase during the AM and how many people made the purchase during PM ? **\n", "\n", "**(Hint: Check out [value_counts()](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html) ) **" ] }, { "cell_type": "code", "execution_count": 96, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "PM 5068\n", "AM 4932\n", "Name: AM or PM, dtype: int64" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** What are the 5 most common Job Titles? **" ] }, { "cell_type": "code", "execution_count": 97, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Interior and spatial designer 31\n", "Lawyer 30\n", "Social researcher 28\n", "Purchasing manager 27\n", "Designer, jewellery 27\n", "Name: Job, dtype: int64" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** Someone made a purchase that came from Lot: \"90 WT\" , what was the Purchase Price for this transaction? **" ] }, { "cell_type": "code", "execution_count": 99, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "513 75.1\n", "Name: Purchase Price, dtype: float64" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** What is the email of the person with the following Credit Card Number: 4926535242672853 **" ] }, { "cell_type": "code", "execution_count": 100, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "1234 bondellen@williams-garza.com\n", "Name: Email, dtype: object" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** How many people have American Express as their Credit Card Provider *and* made a purchase above $95 ?**" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Address 39\n", "Lot 39\n", "AM or PM 39\n", "Browser Info 39\n", "Company 39\n", "Credit Card 39\n", "CC Exp Date 39\n", "CC Security Code 39\n", "CC Provider 39\n", "Email 39\n", "Job 39\n", "IP Address 39\n", "Language 39\n", "Purchase Price 39\n", "dtype: int64" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** Hard: How many people have a credit card that expires in 2025? **" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "1033" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "** Hard: What are the top 5 most popular email providers/hosts (e.g. gmail.com, yahoo.com, etc...) **" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "hotmail.com 1638\n", "yahoo.com 1616\n", "gmail.com 1605\n", "smith.com 42\n", "williams.com 37\n", "Name: Email, dtype: int64" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Great Job!" ] } ], "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.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }