Product Trend Analysis Project with Python

Data Analytics project 10

Product Trend Analysis Project with Python

Build a complete product trend analysis portfolio project with documented metrics, reproducible Python code, validation checks, and responsible interpretation.

Explore Data Analytics training in VizagView all project ideas

Business question

Which products are gaining or losing revenue and share after accounting for annual seasonality?

Dataset and grain

Two years of seeded synthetic monthly revenue for four fictional products.

Requirements

Python 3.10 or later with numpy and pandas installed.

Method and validation checks

Shift product revenue by 12 months, calculate year-over-year growth, calculate same-month total revenue, and derive product revenue share.

  • Prior-year values are shifted within product only
  • Latest product shares sum to one
  • First-year year-over-year values remain missing
  • Growth and share are not interpreted as causal drivers

Complete Python code

Save the code as da_product_trend_analysis.py. Review the stated model and field assumptions before using another dataset.

"""Analyse product revenue, share, and year-over-year trends."""

from __future__ import annotations

import numpy as np
import pandas as pd


def make_demo_product_sales(seed: int = 42) -> pd.DataFrame:
    rng = np.random.default_rng(seed)
    months = pd.date_range("2024-01-01", "2025-12-01", freq="MS")
    products = ["Alpha", "Beta", "Gamma", "Delta"]
    rows = []
    for p_index, product in enumerate(products):
        for index, month in enumerate(months):
            base = (85_000 + p_index * 18_000) * (1 + (0.018 - p_index * 0.003) * index)
            rows.append((month, product, max(base + rng.normal(0, 7_000), 0)))
    return pd.DataFrame(rows, columns=["month", "product", "revenue"])


def analyse_products(data: pd.DataFrame) -> tuple[pd.DataFrame, pd.DataFrame]:
    monthly = data.copy().sort_values(["product", "month"])
    monthly["revenue_previous_year"] = monthly.groupby("product")["revenue"].shift(12)
    monthly["yoy_growth"] = monthly["revenue"] / monthly["revenue_previous_year"] - 1
    monthly["month_total"] = monthly.groupby("month")["revenue"].transform("sum")
    monthly["revenue_share"] = monthly["revenue"] / monthly["month_total"]
    latest_month = monthly["month"].max()
    latest = monthly[monthly["month"] == latest_month].sort_values("yoy_growth", ascending=False)
    return monthly, latest[["product", "revenue", "revenue_share", "yoy_growth"]]


def main() -> None:
    _, latest = analyse_products(make_demo_product_sales())
    print(latest.round(3).to_string(index=False))
    print("Year-over-year growth controls for seasonality but does not explain the cause of change.")


if __name__ == "__main__":
    main()

Build and run the project

Run python da_product_trend_analysis.py to compare latest product revenue, share, and year-over-year growth.

  1. Confirm the source grain and field definitions.
  2. Reconcile record counts and additive totals.
  3. Validate rate denominators and date filters.
  4. Review outliers and missing values.
  5. Read the interpretation limits before sharing conclusions.

Expected analytical output

A monthly product table and latest-month ranking with revenue, share, and year-over-year growth.

Interpretation and responsible-use limits

Synthetic trends do not represent real demand. Revenue can change because of price, volume, mix, availability, returns, or reporting rules; a trend table alone cannot identify cause.

Ways to extend the project

Decompose price, volume, and mix; add units and availability; compare cohorts and regions; annotate launches; and quantify uncertainty.

Continue learning Data Analytics

Try the next project, return to the Softenant project library, or explore the Data Analytics course in Vizag for guided SQL, Excel, Power BI, Python, dashboard, and portfolio practice.