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.
Please excuse anything that doesn't make "Real-World" sense in the dataframe, all the data is fake and made-up.
Also note that all of these questions can be answered with one line of code.
Import pandas and read in the Ecommerce Purchases csv file and set it to a DataFrame called ecom.
import pandas as pd
ecom = pd.read_csv('Ecommerce Purchases.csv')
Check the head of the DataFrame.
ecom.head()
How many rows and columns are there?
ecom.info()
What is the average Purchase Price?
ecom['Purchase Price'].mean()
What were the highest and lowest purchase prices?
ecom['Purchase Price'].max(), ecom['Purchase Price'].min()
How many people have English 'en' as their Language of choice on the website?
ecom[ecom['Language']=='en'].shape[0]
How many people have the job title of "Lawyer" ?
ecom[ecom['Job'] == 'Lawyer'].shape[0]
How many people made the purchase during the AM and how many people made the purchase during PM ?
(Hint: Check out value_counts() )
ecom['AM or PM'].value_counts()
What are the 5 most common Job Titles?
ecom['Job'].value_counts().head(5)
Someone made a purchase that came from Lot: "90 WT" , what was the Purchase Price for this transaction?
ecom[ecom['Lot']=='90 WT']['Purchase Price']
What is the email of the person with the following Credit Card Number: 4926535242672853
ecom[ecom["Credit Card"] == 4926535242672853]['Email']
How many people have American Express as their Credit Card Provider and made a purchase above $95 ?
ecom[(ecom['CC Provider']=='American Express') & (ecom['Purchase Price']>95)].shape[0]
How many people have a credit card that expires in 2025?
sum(ecom['CC Exp Date'].apply(lambda x: x[3:]) == '25')
sum(ecom['CC Exp Date'].str.contains('/25'))
What are the top 5 most popular email providers/hosts (e.g. gmail.com, yahoo.com, etc...)
ecom['Email'].apply(lambda x: x.split('@')[1]).value_counts().head(5)
def getHost(x):
return x.split('@')[1]
ecom['Email'].apply(getHost).value_counts().head(5)