Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

E-commerce Customer Behaviour Analysis with Python

E-commerce Customer Behaviour Analysis with Python

Overview

This project analyses a synthetic e-commerce transaction dataset to understand sales performance, customer behaviour, product and category performance, and monthly trends. I built it to refresh and consolidate my Python data analysis skills, especially data cleaning, Pandas grouping and aggregation, visualisation, and turning analysis into practical business observations.

Business Questions

  1. Which categories and regions generated the most revenue?
  2. How do repeat customers compare with one-time customers?
  3. Which customer groups generated the most value?
  4. Which product categories had stronger prices, margins and return rates?
  5. How did revenue, orders, average order value and return rate change over time?

Dataset

  • Source: Kaggle E-commerce Sales Transactions Dataset
  • Records: 34,500 transaction records
  • Original columns: 17
  • Cleaned columns: 25, after adding revenue, time fields, a return flag and age group
  • Date range: 12 September 2023 to 11 September 2025
  • Original fields include order ID, customer ID, product ID, category, price, discount, quantity, payment method, order date, delivery time, region, return status, total amount, shipping cost, profit margin, customer age and gender.

The dataset is synthetic, so the findings are for practice and portfolio demonstration rather than real commercial decision-making.

Tools Used

  • Python
  • Pandas
  • NumPy
  • Matplotlib
  • Seaborn
  • Jupyter Notebook
  • VS Code
  • Git and GitHub

Project Workflow

  1. Data overview
  2. Data cleaning
  3. Sales analysis
  4. Customer analysis
  5. Product and category analysis
  6. Trend analysis
  7. Final summary

Key Findings

  • The dataset contains 34,500 transaction records, with no missing values and no duplicated rows.
  • Total revenue was $5,865,293.05 across 34,500 orders.
  • The dataset includes 7,903 customers and 24,912 products.
  • Average order value was $170.01.
  • Electronics generated the highest revenue at $3,319,206.50, followed by Home at $1,077,681.52 and Sports at $629,825.54.
  • Regional revenue was more balanced, with South and North generating the highest revenue.
  • Repeat customers generated most of the revenue:
    • One-time customers: 475 customers, $84,117.69 total revenue, $177.09 average revenue
    • Repeat customers: 7,428 customers, $5,781,175.36 total revenue, $778.30 average revenue
  • Customer value was unevenly distributed, with high-value customers generating the largest share of revenue.
  • Fashion had the highest return rate at 8.28%, followed by Electronics at 7.30%.
  • Grocery had the lowest return rate at 1.31%, but it was the only category with a negative average profit margin at about -2.26%.
  • Electronics had the highest average profit margin at about 55.72%, followed by Home at about 47.86% and Sports at about 38.49%.
  • Monthly revenue was mostly stable across full months, roughly between $215K and $280K.
  • Monthly orders were mostly stable, roughly between 1,350 and 1,500 orders.
  • Average order value fluctuated more than order volume, roughly between $154 and $189.
  • The first and last months are partial months because the dataset starts on 12 September 2023 and ends on 11 September 2025.

Visuals

Revenue by Category

Profit Margin by Category

Total Revenue by Customer Type

Total Revenue by Value Group

Monthly Revenue Trend

Recommendations

  • Prioritise Electronics, Home and Sports because they combine strong revenue, higher price points and stronger margins.
  • Review Fashion returns, as it has the highest category return rate.
  • Review Grocery pricing, discounting and cost assumptions because it has a negative average profit margin.
  • Track repeat customers and high-value customers separately, as repeat customers generate the majority of revenue.
  • Monitor revenue, order volume and average order value together, as revenue movement is not explained by order volume alone.

Limitations

  • The dataset is synthetic, so it does not reflect real customer behaviour with full reliability.
  • Most product IDs appear only once, so individual product-level analysis is limited.
  • The dataset does not include marketing channel, acquisition cost, detailed geography, product names or a real cost breakdown.
  • The first and last months are partial months, so they should not be compared directly with full months.
  • profit_margin is already stored as percentage points, so it should not be multiplied by 100.

What I Learned

  • Loading CSV files into Pandas
  • Checking data quality, missing values and duplicates
  • Converting date fields and creating time-based columns
  • Creating new analysis columns, including revenue, return flag and age group
  • Using groupby and aggregation for business questions
  • Building customer-level summaries
  • Creating customer value groups with qcut
  • Visualising category performance and monthly trends
  • Writing business-focused insights from analysis outputs
  • Checking assumptions carefully, including product-level reliability and profit margin units

How to Run

  1. Clone the repository.
  2. Install the required packages.
  3. Open the notebooks in VS Code or Jupyter Notebook.
  4. Run the notebooks in order from 01 to 07.
pip install -r requirements.txt

Repository Structure

ecommerce-customer-analysis-python/
|-- README.md
|-- requirements.txt
|-- .gitignore
|-- data/
|   |-- raw/
|   |   `-- ecommerce_sales_34500.csv
|   `-- cleaned/
|       `-- ecommerce_sales_cleaned.csv
|-- notebooks/
|   |-- 01_data_overview.ipynb
|   |-- 02_data_cleaning.ipynb
|   |-- 03_sales_analysis.ipynb
|   |-- 04_customer_analysis.ipynb
|   |-- 05_product_analysis.ipynb
|   |-- 06_trend_analysis.ipynb
|   `-- 07_final_summary.ipynb
|-- images/
`-- scripts/

About

My original project demonstrating my Python skills

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages