Sales Analysis Data Science Project with Python

Data Science project 05

Sales Analysis Data Science Project with Python

Build a complete sales analysis workflow with reproducible Python code, traceable calculations, validation checks, and honest limitations.

Explore Data Science training in VizagView all project ideas

Analysis question

What are total revenue, monthly movement, and category contribution in the demonstration order data?

Dataset

A seeded synthetic year of 1,200 orders across four regions and three product categories, with quantities and unit prices.

Requirements

  • Python 3.10 or later
  • A terminal or command prompt
  • python -m pip install numpy pandas
  • About 45-60 minutes to build and review

Method and data checks

Calculate line revenue, convert dates to monthly periods, aggregate monthly revenue, calculate month-over-month growth, and rank category revenue.

  • Revenue equals quantity multiplied by unit price
  • Orders are counted by unique ID
  • Months are sorted chronologically
  • The first growth value remains missing because no prior month exists

Complete Python code

Save the program as ds_sales_analysis.py. The dataset generator or loader, analysis functions, output, and reproducibility controls are included.

"""Sales KPI analysis on reproducibly generated orders."""

from __future__ import annotations

import numpy as np
import pandas as pd


def make_demo_sales(n: int = 1_200, seed: int = 42) -> pd.DataFrame:
    rng = np.random.default_rng(seed)
    dates = pd.Timestamp("2025-01-01") + pd.to_timedelta(rng.integers(0, 365, n), unit="D")
    category = rng.choice(["Courses", "Books", "Software"], n, p=[0.5, 0.3, 0.2])
    unit_price = np.select([category == "Courses", category == "Books"], [rng.integers(2500, 12000, n), rng.integers(300, 1500, n)], default=rng.integers(1200, 6000, n))
    return pd.DataFrame({"order_id": range(1, n + 1), "date": dates, "region": rng.choice(["North", "South", "East", "West"], n), "category": category, "quantity": rng.integers(1, 5, n), "unit_price": unit_price})


def analyse_sales(data: pd.DataFrame) -> dict[str, object]:
    sales = data.copy()
    sales["revenue"] = sales["quantity"] * sales["unit_price"]
    sales["month"] = pd.to_datetime(sales["date"]).dt.to_period("M").astype(str)
    monthly = sales.groupby("month", as_index=False)["revenue"].sum()
    monthly["growth_pct"] = monthly["revenue"].pct_change() * 100
    category = sales.groupby("category", as_index=False)["revenue"].sum().sort_values("revenue", ascending=False)
    return {"total_revenue": float(sales["revenue"].sum()), "orders": int(sales["order_id"].nunique()), "monthly": monthly, "category": category}


def main() -> None:
    result = analyse_sales(make_demo_sales())
    print(f"Revenue: {result['total_revenue']:,.0f} | Orders: {result['orders']}")
    print(result["category"].to_string(index=False))
    print("\nMonthly trend:\n", result["monthly"].round(2).to_string(index=False))


if __name__ == "__main__":
    main()

Run the project

  1. Create and activate a virtual environment.
  2. Install dependencies with python -m pip install numpy pandas.
  3. Run python ds_sales_analysis.py.
  4. Reconcile row counts and totals before interpreting patterns.
  5. Read the limitations before substituting any real dataset.

Expected analytical output

Total revenue, unique order count, a monthly revenue and growth table, and category revenue ranking.

Interpretation and responsible-use limits

Synthetic revenue does not represent Softenant or any real company. Growth percentages are descriptive, can be volatile on small bases, and do not establish causes.

Ways to extend the project

Add targets, discounts, taxes, returns, sales channels, contribution margin, cohort retention, and variance explanations tied to a governed data dictionary.

Continue learning Data Science

Try the next project, return to the Softenant project library, or explore the Data Science course in Vizag for guided data cleaning, analysis, visualisation, and portfolio feedback.