TutorialsPythonCapstone Project — Sales Analysis

Capstone Project — Sales Analysis

End-to-end data analysis project: load, clean, analyse and visualise sales data

This capstone project walks you through a complete data analysis workflow — the kind of task you will do in a data analyst role. Starting from a raw CSV file, you will clean the data, compute business metrics, perform EDA, and generate a visualised summary report. This project is the type of portfolio piece that impresses interviewers at Noida and Delhi NCR companies.

Example

Complete sales analysis script
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# ── 1. LOAD ──────────────────────────────────────────────────────
df = pd.read_csv("sales_2026.csv",
                  parse_dates=["OrderDate"],
                  dtype={"OrderID": str})
print(f"Loaded: {df.shape[0]:,} rows × {df.shape[1]} columns")

# ── 2. CLEAN ─────────────────────────────────────────────────────
# Standardise columns
df.columns = df.columns.str.strip().str.lower().str.replace(" ", "_")

# Fix data types
df["amount"] = pd.to_numeric(df["amount"], errors="coerce")
df["city"]   = df["city"].str.strip().str.title()

# Handle nulls
print(df.isnull().sum())
df.dropna(subset=["order_id", "amount"], inplace=True)
df["region"].fillna("Unknown", inplace=True)

# Remove duplicates
df.drop_duplicates(subset=["order_id"], inplace=True)

# ── 3. FEATURE ENGINEERING ───────────────────────────────────────
df["month"]   = df["orderdate"].dt.to_period("M").astype(str)
df["quarter"] = df["orderdate"].dt.quarter.map({1:"Q1",2:"Q2",3:"Q3",4:"Q4"})
df["profit"]  = df["amount"] - df["cost"]
df["margin"]  = (df["profit"] / df["amount"] * 100).round(1)

# ── 4. AGGREGATE ─────────────────────────────────────────────────
region_summary = df.groupby("region").agg(
    Revenue =("amount", "sum"),
    Orders  =("order_id", "count"),
    Margin  =("margin", "mean"),
).sort_values("Revenue", ascending=False)

monthly = df.groupby("month")["amount"].sum().reset_index()

# ── 5. VISUALISE ─────────────────────────────────────────────────
fig, axes = plt.subplots(2, 2, figsize=(14, 10))
fig.suptitle("Sales Analysis Report 2026", fontsize=16, fontweight="bold")

# Revenue by Region
region_summary["Revenue"].plot(kind="barh", ax=axes[0,0], color="#0a1628")
axes[0,0].set_title("Revenue by Region")

# Monthly trend
axes[0,1].plot(monthly["month"], monthly["amount"]/1e6, marker="o", color="#c47f00")
axes[0,1].set_title("Monthly Revenue (₹ Millions)")
axes[0,1].tick_params(axis="x", rotation=45)

# Margin distribution
axes[1,0].hist(df["margin"], bins=40, color="#16a34a", edgecolor="white")
axes[1,0].set_title("Profit Margin Distribution")

# Quarterly comparison
df.groupby("quarter")["amount"].sum().plot(kind="bar", ax=axes[1,1], color="#7c3aed")
axes[1,1].set_title("Revenue by Quarter")

plt.tight_layout()
plt.savefig("Sales_Analysis_2026.png", dpi=150)
plt.show()
print("Analysis complete!")

Key Points

  • Always structure scripts: Load → Clean → Feature Engineer → Aggregate → Visualise
  • Print df.shape after every major step to verify you haven't accidentally lost rows
  • subplot(2, 2) creates a 2×2 grid of charts — efficient for dashboards
  • Export charts with plt.savefig() for presentations and reports
  • This script is a portfolio project — push it to GitHub with a README

Practice Question

In the capstone workflow, which step comes immediately BEFORE visualisation?

Related Topics

Exploratory Data Analysis (EDA) WorkflowA systematic 6-step EDA process every data analyst should follow on any new datasetgroupby and Pivot TablesAggregate data by category with groupby — the Pandas equivalent of Excel pivot tablesMatplotlib BasicsCreate line charts, bar charts and scatter plots with Python's core plotting libraryFeature Engineering for AnalystsCreate new meaningful columns from existing data to improve analysis and modelling