Compare wholesale sales growth and inventory in Python

Compare wholesale sales growth, inventory growth and published inventory-to-sales ratios using Census MWTS data.

Compare wholesale sales growth with inventory

A supply-chain analyst wants to see whether wholesale inventories are moving with sales. This example compares machinery wholesalers and grocery wholesalers from December 2024 to December 2025 using Census Monthly Wholesale Trade Survey estimates. It puts sales growth beside inventory growth and the published inventory-to-sales ratio.

The optional input.csv contains two genuine industry selections: machinery, equipment and supplies (4238) and grocery and related products (4244). The same choices appear in the selections list in the Python code below. The observations come from Census; no business records or measurements are invented.

Download monthly_observations.csv into your working folder. This is a genuine subset of the purchased table: 288 monthly records for those two groups during 2024–2025, with sales, inventories and ratios in adjusted and unadjusted form. All 23 fields are unchanged. The full $29 edition contains 53,856 monthly records across 132 series, plus eight supporting tables. Inspect the complete product.

Code example

Paste this standard-library example into a notebook cell, IPython or a script. It selects seasonally adjusted values, checks that the required months and measures are present, and prints two comparisons.

Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.

Python 3.10+ · Jupyter, IPython or a script
import csv
from decimal import Decimal

# These are real Census business categories, also listed in example_input.csv.
selections = [{'group_code': '4238'}, {'group_code': '4244'}]
start, end = '2024-12', '2025-12'
selected = {r['group_code'] for r in selections}
observations = {}
with open('monthly_observations.csv', newline='', encoding='utf-8') as f:
    for row in csv.DictReader(f):
        if row['group_code'] not in selected or row['seasonal'] != 'SA' or row['month'] not in {start, end}:
            continue
        key = row['group_code'], row['measure_code'], row['month']
        if key in observations:
            raise ValueError('Duplicate observation: ' + str(key))
        if row['availability'] != 'reported':
            raise ValueError('Selected value unavailable: ' + str(key))
        observations[key] = row

results = []
for selection in selections:
    group = selection['group_code']
    required = [(group, measure, month) for measure in ('SALES', 'INVENTORY', 'RATIO') for month in (start, end)]
    if any(key not in observations for key in required):
        raise ValueError('Selected comparison is incomplete: ' + group)
    value = lambda measure, month: Decimal(observations[group, measure, month]['value'])
    sales_growth = 100 * (value('SALES', end) / value('SALES', start) - 1)
    inventory_growth = 100 * (value('INVENTORY', end) / value('INVENTORY', start) - 1)
    ratio_change = value('RATIO', end) - value('RATIO', start)
    name = observations[group, 'SALES', end]['group_name']
    results.append(dict(group_code=group, group_name=name, sales_change_percent=f'{sales_growth:.2f}',
                        inventory_change_percent=f'{inventory_growth:.2f}', inventory_sales_ratio=f'{value("RATIO", end):.2f}', ratio_change=f'{ratio_change:+.2f}'))
    print(f'{name}: sales {sales_growth:+.2f}%; inventories {inventory_growth:+.2f}%; inventory/sales {value("RATIO", end):.2f} (change {ratio_change:+.2f}).')

Analysis of the output

Machinery, Equipment, & Supplies: sales +3.84%; inventories -0.13%; inventory/sales 2.91 (change -0.12).
Grocery & Related Products: sales +2.69%; inventories +6.45%; inventory/sales 0.72 (change +0.02).

Machinery wholesalers reported 3.84% higher sales and 0.13% lower inventories in December 2025 than in December 2024. Their inventory-to-sales ratio declined by 0.12 to 2.91. The two dollar measures moved in different directions, a distinction that sales growth alone would miss.

Grocery wholesalers reported 2.69% higher sales and 6.45% higher inventories. Their ratio increased by 0.02 to 0.72. Inventory grew faster than sales in this comparison.

The ratio divides month-end inventories by one month of sales. It is not annual inventory turnover or a measure of profit. Differences between machinery and grocery do not establish which industry is better managed: their goods and business models differ. Both dollar measures are nominal, so seasonal adjustment does not remove price changes. These changes are descriptive, not a test of statistical significance.

Compare stages of business activity

The retail and wholesale collection connects the two trading stages with price, payroll and local establishment context. The manufacturing collection adds upstream orders and shipments. Review populations and industry definitions before comparing them; adding wholesale and retail receipts can count successive sales of the same goods.

Using the full dataset

Extract the purchased ZIP and replace the sample with its complete monthly_observations.csv. The example runs unchanged. Change start, end and selections to examine another group or period. Keep group identifiers as text. The observation key is series_id + month; matching measures share group_code + month + seasonal.

groups.csv describes 22 nested wholesale groups. Computer wholesalers (42343) are part of professional/commercial equipment (4234); do not add a subgroup to its parent. Computer estimates begin in 1997. Earlier records have availability=source_not_available, blank numeric values and the original NA marker. They are not zeros.

series.csv and coverage.csv show reported periods and availability. Series notes preserve the publisher’s exceptions to seasonal adjustment for paper and chemical inventories. annual_sales.csv retains Census’s NSA annual totals. Do not sum inventory stocks across months.

ratio_checks.csv compares every numeric ratio with its sales and inventory counterparts. It flags 84 historical values outside the rounding bounds. Census’s original values remain unchanged; we have not established the cause. Review those flags before interpreting small historical ratio changes. The four ratios used in this example pass that comparison.

sampling_variability.csv contains published sales/inventory coefficients of variation (percent) and ratio standard errors (ratio units) for March 2013–December 2025. Census bases these on NSA data and recommends them for both adjusted and unadjusted estimates. They are not standard errors of year-over-year change, and this table does not supply the covariance needed for a change test.

Sources and versions

Source: Census MWTS workbooks, October 26, 2026 annual revision, retained November 8, 2026 UTC. The product covers January 1992–December 2025 as revised in that edition, on the source’s 2017 NAICS basis. Partial 2026 is excluded. This is a retained source edition, not a sequence of original monthly-release vintages.

The annual-revision notice documents exceptional 2023/2024 inventory constraints for motor-vehicle and computer wholesalers; their MWTS estimates need not match published AIES inventories. The definitions explain the merchant-wholesale population, which excludes manufacturers’ sales branches/offices and agents/brokers.

Census provides the source workbooks free. ACD sells preparation, checks, documentation and delivery. Processing improvements and publisher error corrections to your purchased edition are included; new source publications may be sold separately. Read the source and preparation record.

Example checked November 8, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.