Instacart Online Shopping Analysis

Tools: Python, Jupyter Notebooks

Posted by Graham Field on February 04, 2024 · 11 mins read

Introduction

Instacart is a real online grocer that has made some of its data available for download and use. The customer dataset used as part of the analysis was synthesized and contains data on the number of dependencies, income, and more.

Tools:

  • Python
  • Jupyter Notebooks
  • Libraries: Pandas, Numpy, Seaborn, Matplotlib

Data:

  • Open Source Data
  • 3 Million Rows
  • 23 Numeric and Categorical variables
  • Joins: Order, Product, Customers, and Department

Key Research Questions

  • What are the busiest days of the week?
  • When are the busiest hours of the day?
  • Are there particular times of the day when spending is the highest?
  • Who is placing the most orders?
  • Which product departments are more popular than others?
  • What is the distribution among users with regards to their brand loyalty and frequency of re-order and expenditure using mean, max, and min?
  • Is there a connection between age and family status in terms of ordering habits?

Step 1: Initial Data Exploration and Cleaning

In the first step of the analysis, I conducted an initial analysis to gain an understanding of the shape and size of the data frames I was going to be dealing with.

Next, I needed to check for missing and duplicated data. Some rows needed to be deleted while others had missing values due to only a single order being placed in the history of the user.

Data Cleaning

Step 2: Data Wrangling

In this step, I identified unnecessary columns and dropped them from the data frame. Several columns were also renamed for ease of use and legibility. Some of the data types needed to be changed from integer to string.

Column Renaming Renaming of a column Dropping Columns Dropping unnecessary columns

For privacy reasons, all personal information which could lead to the identification of individuals was removed, such as first and last names as well as addresses. This data is regularly updated and free to use for research purposes.

Step 3: Merging Data Sets

Before merging the two data frames, I checked the shape of the data frames, looking at the number of rows and columns in each. This helped in selecting the correct type of join.

I used the “product_id” column as both data frames had this column. I used a left join in Python to merge two data frames so that all records from the left dataframe are included in the result, and only the matching records from the right dataframe are included, ensuring no data from the left dataframe is lost even if there are no corresponding matches in the right dataframe.

Merging Data Frames Merging the two data frames

To confirm the success of the merge, I used a true-false indicator. The absence of false flags indicated a successful join.

Merge Validation

Step 4: Deriving New Variables

To answer the research questions and gain deeper insight into the data, I derived new columns with labels for various parameters. Below is an example of creating price ranges.

I created price ranges for the products, categorized as Low, Mid, and High price ranges.

Price Range Derivation

Using the `loc` function, I created a frequency count for the number of orders within the price ranges, ultimately creating a new column called “Price_range_Loc.”

Creating New Columns

Step 5: Grouping Data

I used the `groupby()` and `transform()` functions to create a column with the maximum number of orders per unique customer id. The `np.max` argument was used to determine the maximum order number for each user.

Grouping Data

I used the loc function again to create a loyalty flag column where the customer were categorised as either “New customer”, Regular “Customer” or “loyal Customer” based on the number of orders.

Loc

The same process was used to derive several more categories, such as order hour of the day for repeat and new customers, income levels (High, Mid, Low), customers with and without dependents, and customers by region, among others.

Step 6: Visual Analysis

Now that I have completed the previous steps I have clean data with new variables that I can work with and visualise. This is my favourite part of the process and where I gain the most insight into the data I am working with.

reorder_rate_by_hour_of_the_day_and_week

The above heat map show the reorder rate by hours of the day and days of the week. We can see that Tuesday in particular has the highest reorder rate and that on all days between 06:00 and 09:00 have the highest re order rates.

Loc

The above Heat map shows order counts by time of day and day of the week. From this visualisation we can see that Monday and Tuesday are particularly busy and that throughout the week between 07:00 and 17:00.

prices_hours

The above chart which shows the highest price paid for orders is between 01:00 and 03:00 am this does not mean that the most orders placed are between these times.

Loc

The above chart shows the distribution of Customers based on their age, income level and weather or not they have dependants. From this we can see that divided into region. From the graph we can see that in all regions it is generally middle-aged and seniors with mid to high level of income that do most of the ordering. the south seems to have the largest customer base.

Loc

The most popular products by far seem to be Fresh Produce, Beverages, Snacks and Eggs.

Recommendations

1. Busiest Days and Hours:

Busiest Days: The busiest days of the week are Friday, Saturday, and Sunday. Marketing should focus on advertising upsells and cross-sells during these days. To encourage higher frequency of orders during the week, advertise staples such as produce and eggs from Monday to Thursday.

Optimal Timing for Reorders: For reorders, focus on upsells and cross-sells on Sunday morning, two days before the busiest period.

2. Spending Patterns:

Peak Spending Times: Spending is highest between 09:00 and 17:00. There is a correlation between the number of orders and expenditure during these hours. Marketing should target these times.

Daily Spending Trends: The average price per order peaks on Friday and Sunday, indicating that customers are willing to spend more on these days. Stronger advertising should be considered for these days.

High Price Orders: The highest prices paid for orders occur between 01:00 and 03:00 AM, though this does not coincide with the highest order volumes.

3. Customer Demographics:

Frequent Buyers: High earners, particularly those with dependents, place the most orders. Marketing should focus on these groups. Additionally, adults and seniors represent large market segments, so advertising targeted at these demographics would be beneficial.

4. Popular Product Departments:

Top Departments: Produce, Beverages, Snacks, and Dairy/Eggs are the most popular departments. Marketing should focus on these categories to retain and attract customers.

Incentives: Consider pairing popular products with lower-selling items to boost sales. Soda is the best-selling product across all regions, so advertising this could attract new customers. Fruits are also among the top-selling products.

5. User Distribution and Brand Loyalty:

Regional Trends: The South has the highest order count, primarily from high earners. Middle earners show consistent ordering patterns across all regions. Interestingly, individuals without dependents in the Midwest order significantly higher-priced items than other regions.

Income Insights: Adults with high income and no dependents have the highest earnings, though they do not place the most orders. Targeting this group with specific marketing could increase high-end sales.

Reflections

This project has been very insightful, demonstrating how grouping and categorizing data can reveal trends and patterns among different demographics. Combining data and deriving new variables provided a wealth of new information. Managing the large amount of data and creating relevant, understandable visualizations was challenging but crucial for effective analysis.