Online shopping decisions rely on how consumers engage with online store content. You work for a new startup company that has just launched a new online shopping website. The marketing team asks you, a new data scientist, to review a dataset of online shoppers' purchasing intentions gathered over the last year. Specifically, the team wants you to generate some insights into customer browsing behaviors in November and December, the busiest months for shoppers. You have decided to identify two groups of customers: those with a low purchase rate and returning customers. After identifying these groups, you want to determine the probability that any of these customers will make a purchase in a new marketing campaign to help gauge potential success for next year's sales.
Data description:
You are given an online_shopping_session_data.csv that contains several columns about each shopping session. Each shopping session corresponded to a single user.
| Column | Description |
|---|---|
SessionID | unique session ID |
Administrative | number of pages visited related to the customer account |
Administrative_Duration | total amount of time spent (in seconds) on administrative pages |
Informational | number of pages visited related to the website and the company |
Informational_Duration | total amount of time spent (in seconds) on informational pages |
ProductRelated | number of pages visited related to available products |
ProductRelated_Duration | total amount of time spent (in seconds) on product-related pages |
BounceRates | average bounce rate of pages visited by the customer |
ExitRates | average exit rate of pages visited by the customer |
PageValues | average page value of pages visited by the customer |
SpecialDay | closeness of the site visiting time to a specific special day |
Weekend | indicator whether the session is on a weekend |
Month | month of the session date |
CustomerType | customer type |
Purchase | class label whether the customer make a purchase |
# Import required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
# Load and view you data
shopping_data = pd.read_csv('online_shopping_session_data.csv')
shopping_data.head()# Start your code here!
# Use as many cells as you likeshopping_data.info()shopping_data['CustomerType'].value_counts()1 - Calculate online purchase rates by customer
# Subset the DataFrame for November and December shopping sessions
shopping_nd = shopping_data[shopping_data['Month'].isin(['Nov', 'Dec'])]
shopping_nd.head()shopping_nd.sample(5)shopping_nd.shape# Calculate the frequency of sessions by customer type
# Get row counts for CustomerTypes
session_count = shopping_nd.groupby('CustomerType')['Purchase'].value_counts()
print(session_count)# Get total number of sessions by CustomerType
total_new = np.sum(session_count['New_Customer'])
total_returning = np.sum(session_count['Returning_Customer'])
print(total_new)
print(total_returning)# Get number of purchases by CustomerType
purchase_new = session_count[('New_Customer', 1)]
purchase_returning = session_count[('Returning_Customer', 1)]
print(purchase_new)
print(purchase_returning)# Calculate purchase rates by customer type
ratio_new = purchase_new / total_new
ratio_returning = purchase_returning / total_returning
print(ratio_new)
print(ratio_returning)# Create dictionary of customer types and ratios
purchase_rates = {'Returning_Customer': ratio_returning, 'New_Customer': ratio_new}
print(purchase_rates)