Retail Inventory Analysis Project

Data Analytics project 18

Retail Inventory Analysis Project

Build a complete retail inventory 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

Where are stockouts, excess weeks of supply, and slow-moving inventory value concentrated across stores?

Dataset and grain

One thousand synthetic store-SKU rows with on-hand units, recent weekly demand, unit cost, and days since last sale.

Requirements

Python 3.10 or later with numpy and pandas installed.

Method and validation checks

Calculate inventory value and weeks of supply, flag zero-stock and 90-day slow-moving rows, then aggregate store counts, medians, and rates.

  • SKU counts reconcile across stores
  • Inventory value uses on-hand units times unit cost
  • Zero demand does not create infinite weeks of supply
  • Slow-moving value excludes zero-stock rows

Complete Python code

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

"""Analyse store-SKU stock position, ageing, and weeks of supply."""

from __future__ import annotations

import numpy as np
import pandas as pd


def make_demo_store_inventory(n: int = 1_000, seed: int = 42) -> pd.DataFrame:
    rng = np.random.default_rng(seed)
    weekly_demand = rng.gamma(3.0, 8.0, n)
    on_hand = rng.integers(0, 240, n)
    return pd.DataFrame({"store": rng.choice(["Store A", "Store B", "Store C", "Store D"], n),
                         "sku": [f"SKU{i:04d}" for i in range(1, n + 1)], "on_hand_units": on_hand,
                         "average_weekly_demand": weekly_demand.round(2), "unit_cost": rng.uniform(60, 4000, n).round(2),
                         "days_since_last_sale": rng.integers(0, 181, n)})


def analyse_store_inventory(data: pd.DataFrame) -> tuple[dict[str, float], pd.DataFrame]:
    inv = data.copy()
    inv["inventory_value"] = inv["on_hand_units"] * inv["unit_cost"]
    inv["weeks_of_supply"] = inv["on_hand_units"] / inv["average_weekly_demand"].replace(0, np.nan)
    inv["stockout"] = inv["on_hand_units"] == 0
    inv["slow_moving"] = (inv["days_since_last_sale"] >= 90) & (inv["on_hand_units"] > 0)
    kpis = {"inventory_value": float(inv["inventory_value"].sum()), "stockout_rate": float(inv["stockout"].mean()), "slow_moving_value": float(inv.loc[inv["slow_moving"], "inventory_value"].sum())}
    stores = inv.groupby("store", as_index=False).agg(skus=("sku", "nunique"), inventory_value=("inventory_value", "sum"), median_weeks_supply=("weeks_of_supply", "median"), stockout_rate=("stockout", "mean"), slow_moving_rate=("slow_moving", "mean"))
    return kpis, stores


def main() -> None:
    kpis, stores = analyse_store_inventory(make_demo_store_inventory())
    print({k: round(v, 3) for k, v in kpis.items()})
    print(stores.round(3).to_string(index=False))
    print("Weeks of supply assumes recent average demand continues; seasonal stock needs richer logic.")


if __name__ == "__main__":
    main()

Build and run the project

Run python da_retail_inventory_analysis.py to create store-level stock, ageing, and weeks-of-supply KPIs.

  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

Overall inventory value, stockout rate, slow-moving value, and store-level inventory metrics.

Interpretation and responsible-use limits

Weeks of supply assumes recent average demand continues. Seasonal, promotional, perishable, constrained, or intermittent-demand items need different replenishment logic.

Ways to extend the project

Add store-SKU uniqueness checks, ageing bands, markdown risk, service levels, lead times, transfers, seasonal forecasts, and exception drill-through.

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.