Wayfair · Data Analytics
E-commerce Sales Analysis
The work
- In [1]:
import pandas as pd import numpy as np import matplotlib.pyplot as plt - In [2]:
monthly_revenue = pd.read_csv('..\\visualizations\\chart_data\\monthly_revenue.csv') - In [3]:
category_revenue = pd.read_csv('..\\visualizations\\chart_data\\category_revenue.csv') - In [4]:
category_returns_cancelled = pd.read_csv('..\\visualizations\\chart_data\\category_returns_cancelled.csv') Monthly revenue trend - Line chart
- In [5]:
monthly_revenue.head()month monthly_revenue 0 2024-01-01 54107.56 1 2024-02-01 62945.69 2 2024-03-01 70885.83 3 2024-04-01 64177.27 4 2024-05-01 72246.90
- In [6]:
plt.plot(monthly_revenue['month'], monthly_revenue['monthly_revenue'],marker='o',color='blue') plt.title('Monthly Revenue') plt.xlabel('Month') plt.ylabel('Revenue ($)') plt.grid(True,alpha=0.5) plt.xticks(rotation=45, ha='right') plt.show()<Figure size 640x480 with 1 Axes>
Category revenue comparison - Bar chart
- In [7]:
category_revenuecategory revenue 0 furniture 318593.13 1 kitchen 276103.06 2 decor 274367.49 3 bedding 264321.26 4 outdoor 244097.30 5 lighting 234583.07 6 storage 137978.01 7 bath 108077.68
- In [8]:
category_revenue.plot(x='category', y='revenue',kind='bar',color='green') plt.title('Revenue by Category') plt.xlabel('Category') plt.ylabel('Revenue ($)') plt.xticks(rotation=45, ha='right') plt.grid(axis='y', alpha=0.5) plt.show()<Figure size 640x480 with 1 Axes>
Category-wise return/cancellation rates - Grouped bar chart
- In [9]:
category_returns_cancelledcategory returend_percentage cancelled_percentage 0 bath 4.44 4.56 1 bedding 5.06 3.28 2 decor 4.18 3.48 3 furniture 11.72 3.08 4 kitchen 4.15 3.80 5 lighting 3.99 2.93 6 outdoor 4.43 3.70 7 storage 4.15 3.35
- In [10]:
category_returns_cancelled.plot(x='category', y=['returend_percentage','cancelled_percentage'],kind='bar',color=['orange','red']) plt.title('Returns and Cancellations by Category') plt.xlabel('Category') plt.ylabel('Percentage (%)') plt.xticks(rotation=45, ha='right') plt.grid(axis='y', alpha=0.5) plt.legend(['Returned Percentage', 'Cancelled Percentage']) plt.show()<Figure size 640x480 with 1 Axes>
E-Commerce Sales Analysis
Project Overview
This project focuses on analyzing e-commerce sales data to understand revenue performance, product and category contributions, customer purchasing patterns, and order return and cancellation trends.
Using SQL and Python, the project explores historical sales data, identifies important business trends, and derives insights that can support better business and sales planning decisions.
Objectives
- Perform data validation and cleaning to ensure data quality.
- Define a consistent revenue calculation methodology.
- Analyze monthly revenue trends and year-over-year performance.
- Identify top-performing products and revenue-generating categories.
- Evaluate category-wise return rates, cancellation rates, and average order value.
- Create visualizations to communicate key business insights.
Tools and Technologies
- PostgreSQL: Data querying, cleaning checks, and analytical SQL queries.
- Python: Data analysis and visualization.
- Pandas: Data loading and data manipulation.
- Matplotlib: Creating charts and visualizing trends.
- Jupyter Notebook: Python analysis and visualization workflow.
Dataset Structure
The project uses four datasets:
Source: https://www.datacareerschool.com/datalabs/ecommerce-sales-analysis
| Dataset | Description |
|---|---|
| Customers | Customer information and acquisition details |
| Orders | Order dates, statuses, payment methods, and shipping information |
| Order Items | Products purchased, quantities, unit prices, and discounts |
| Products | Product names, categories, prices, and costs |
Analysis and Methodology
1. Data Validation and Cleaning
Performed initial data-quality checks across the four datasets to identify inconsistencies and duplicate records.
- Orders table: Identified and removed 38 duplicate records.
- Products table: Standardized category names by converting text to lowercase using
str.lower()and removing unnecessary leading and trailing spaces usingstr.strip().
These steps helped maintain consistency and improve the reliability of the analysis.
2. Revenue Definition
To maintain a consistent revenue calculation throughout the project, only completed orders were considered revenue-generating orders.
Net Revenue = (Quantity × Unit Price) − Discount Amount
- Completed orders were included.
- Returned and cancelled orders were excluded.
- Discounts were deducted from the gross item value.
This definition was applied consistently across the revenue-related SQL queries.
3. Monthly Revenue Analysis
Analyzed monthly revenue trends and calculated:
- Month-over-Month (MoM) revenue changes.
- Year-over-Year (YoY) revenue changes.
- Absolute revenue change.
- Percentage revenue change.
The analysis identified noticeable monthly revenue movements around October and November, with October showing approximately 9–12% growth and November showing approximately 50–55% growth in the observed comparisons.
December's month-over-month movement was also examined to understand changes in year-end sales performance.
4. Product and Category Analysis
Evaluated product and category performance using revenue and quantity-based metrics.
Key activities included:
- Identifying the highest revenue-generating product categories.
- Calculating the top 10 best-selling products based on total units sold and revenue generated.
- Calculating each category's percentage contribution to total monthly revenue.
- Examining how category revenue contributions changed throughout the year.
Key finding: Furniture, Kitchen, and Decor were among the highest revenue-generating categories.
5. Returns, Cancellations, and Average Order Value
Compared product categories based on their return rates, cancellation rates, and category-level average order value.
Key findings:
- Highest return rate: Furniture, approximately 12%.
- Lowest return rate: Lighting, approximately 4%.
- Highest cancellation rate: Bath, approximately 4.5%.
- Lowest cancellation rate: Lighting, approximately 3%.
- Highest category-level AOV: Furniture, approximately $371.
- Lowest category-level AOV: Bath, approximately $72.
This analysis helps identify categories that generate higher revenue but may also experience greater returns or cancellations.
Note: Category-level AOV represents average net revenue per completed order containing that category.
Visualizations
Three visualizations were created using Python and Matplotlib:
- Monthly Revenue Trend: Displays monthly revenue movements over the analysis period.
- Revenue by Category: Compares the revenue generated by different product categories.
- Returns and Cancellations by Category: Compares return and cancellation percentages across product categories.
Key Business Insights
- Furniture, Kitchen, and Decor are major contributors to overall revenue.
- Furniture generates the highest category-level revenue performance but also has the highest return rate.
- Bath has the highest cancellation rate and the lowest category-level average order value, indicating an area that may require further investigation.
Business Recommendations
- Improve return management: Investigate the reasons behind the high return rate in Furniture and identify opportunities to improve product descriptions, quality checks, and customer expectations.
- Improve underperforming categories: Evaluate the Bath category's high cancellation rate and low average order value. Consider reviewing product assortment, pricing, and customer purchasing experience.
Project Structure
E-Commerce-sales-analysis
┣ analysis
┃ ┣ 1. Sales Performance Analysis.sql
┃ ┣ 2. Customer Behaviour & Retention.sql
┃ ┣ 2. Revenue Defination.sql
┃ ┣ 3. Monthly revenue analysis.sql
┃ ┣ 4. Product and category analysis.sql
┃ ┣ 5. Returns, cancellations and average order value.sql
┃ ┣ create_tables.sql
┃ ┣ EDA-data_cleaning.ipynb
┃ ┣ ERD.pgerd
┃ ┗ visualizations_notebook.ipynb
┣ data
┃ ┣ customers.csv
┃ ┣ orders.csv
┃ ┣ orders_cleaned.csv
┃ ┣ order_items.csv
┃ ┣ products.csv
┃ ┗ products_cleaned.csv
┣ visualizations
┃ ┣ chart_data
┃ ┃ ┣ category_returns_cancelled.csv
┃ ┃ ┣ category_revenue.csv
┃ ┃ ┗ monthly_revenue.csv
┃ ┣ category_revenue.png
┃ ┣ monthly_revenue.png
┃ ┗ returned_cancelled.png
┗ README.mdConclusion
This project demonstrates the use of SQL and Python for practical e-commerce data analysis, from data validation and revenue calculations to business performance analysis and visualization.
The findings provide insights into sales trends, category performance, and order-related issues that can help support data-driven business decisions.
The brief this answers
Clean two years of online store orders and turn them into a clear sales review for next year's plan.
Try it yourselfOther answers to this brief
The same problem, solved by somebody else.
Wayfair · Data AnalyticsE-commerce Sales Analysis
Clean two years of online store orders and turn them into a clear sales review for next year's plan.
- Data cleaning
- pandas
- Time series trends
- easy
Akash Kumar0
Wayfair · Data AnalyticsE-commerce Sales Analysis
Clean two years of online store orders and turn them into a clear sales review for next year's plan.
- Data cleaning
- pandas
- Time series trends
- easy
Goutham Dheekonda0
Wayfair · Data AnalyticsE-commerce Sales Analysis
Clean two years of online store orders and turn them into a clear sales review for next year's plan.
- Data cleaning
- pandas
- Time series trends
- easy
Chethan Reddy Bobbali0
Discussion
Nothing here yet. Ask how they approached it, or tell them what you would have done differently.