TutorialsPythonCapstone: Sales Analysis Project

Capstone: Sales Analysis Project

A complete end-to-end data analysis project — from raw CSV to insights and charts

This capstone combines everything you have learned: loading data, cleaning, aggregating, visualising, and drawing insights. Follow this workflow to build a portfolio project that demonstrates your Python data analyst skills to employers. The dataset: a retail company's sales records with columns: OrderID, OrderDate, Customer, Region, Category, Product, Quantity, UnitPrice, Discount, Profit.

Example

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

sns.set_theme(style="whitegrid")

# ── 1. LOAD ───────────────────────────────────────────────
df = pd.read_csv("retail_sales.csv", parse_dates=["OrderDate"])
print(f"Shape: {df.shape}")
print(df.info())

# ── 2. CLEAN ──────────────────────────────────────────────
df.drop_duplicates(inplace=True)
df.dropna(subset=["OrderID","OrderDate"], inplace=True)
df["Product"] = df["Product"].str.strip().str.title()
df["Region"]  = df["Region"].str.strip().str.upper()

# ── 3. FEATURE ENGINEERING ───────────────────────────────
df["Revenue"]       = df["Quantity"] * df["UnitPrice"] * (1 - df["Discount"])
df["Profit_Margin"] = (df["Profit"] / df["Revenue"] * 100).round(2)
df["Year"]          = df["OrderDate"].dt.year
df["Month"]         = df["OrderDate"].dt.month
df["YearMonth"]     = df["OrderDate"].dt.strftime("%Y-%m")

# ── 4. ANALYSIS ───────────────────────────────────────────
# KPIs
print(f"Total Revenue: ₹{df['Revenue'].sum():,.0f}")
print(f"Total Orders:  {df['OrderID'].nunique():,}")
print(f"Avg Order:     ₹{df['Revenue'].mean():,.0f}")
print(f"Avg Margin:    {df['Profit_Margin'].mean():.1f}%")

# Revenue by region
region_rev = df.groupby("Region")["Revenue"].sum().sort_values(ascending=False)

# Monthly trend
monthly = df.groupby("YearMonth")["Revenue"].sum()

# ── 5. VISUALISE ──────────────────────────────────────────
fig, axes = plt.subplots(1, 2, figsize=(14, 5))

region_rev.plot(kind="bar", ax=axes[0], color="#c47f00", edgecolor="white")
axes[0].set_title("Revenue by Region")
axes[0].set_ylabel("Revenue (₹)")
axes[0].tick_params(axis="x", rotation=30)

monthly.plot(kind="line", ax=axes[1], color="#0284c7", marker="o")
axes[1].set_title("Monthly Revenue Trend")
axes[1].set_ylabel("Revenue (₹)")
axes[1].tick_params(axis="x", rotation=45)

plt.suptitle("Retail Sales Analysis 2026", fontsize=14, fontweight="bold")
plt.tight_layout()
plt.savefig("sales_analysis.png", dpi=150, bbox_inches="tight")
plt.show()
💡 Use a real dataset from Kaggle (search "retail sales dataset") to practise this workflow and add it to your portfolio on GitHub.

Key Points

  • Every project follows: Load → Clean → Engineer Features → Analyse → Visualise
  • Start with df.info() and df.describe() before doing anything else
  • Put KPI numbers at the top of your analysis — they anchor the story
  • Save charts with plt.savefig("name.png", dpi=150) for use in presentations
  • A GitHub repository with this project + a README is a strong portfolio piece for Noida/Delhi NCR job applications

Practice Question

In the capstone workflow, in which step do you create new columns like "Revenue" and "Profit_Margin" from existing columns?