Compare retail sales growth and inventory in Python

Compare retail sales growth, inventory growth and published inventory-to-sales ratios using Census MRTS data.

Compare sales growth with inventory

A retail analyst wants to know whether inventory is moving with sales or accumulating more quickly. This example compares motor vehicle and parts dealers with food and beverage stores from December 2024 to December 2025 using Census Monthly Retail Trade Survey estimates. It puts sales growth beside inventory growth and the published inventory-to-sales ratio.

The optional input.csv contains two genuine category choices: motor vehicle and parts dealers (naics:441) and food and beverage stores (naics:445). The same choices appear in the selections list in the Python code below. The prefix identifies an ACD group key; the original Census NAICS code is retained separately in the data. No observations are invented.

Download monthly_observations.csv into your working folder. This is a genuine subset of the purchased table: 288 monthly records for those categories during 2024–2025, covering sales, inventories and ratios in adjusted and unadjusted form, with all 23 fields unchanged. The full $29 edition supplies 56,304 monthly records across 138 series, plus six reference tables. Inspect the complete product.

Code example

This standard-library example runs in a notebook cell, IPython or a script. It selects seasonally adjusted values, verifies that the comparison has the necessary measures and dates, and prints the results.

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': 'naics:441'}, {'group_code': 'naics:445'}]
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

Motor vehicle and parts dealers: sales -1.17%; inventories -2.10%; inventory/sales 1.93 (change -0.02).
Food and beverage stores: sales +1.13%; inventories +3.34%; inventory/sales 0.81 (change +0.02).

Motor vehicle and parts dealers reported 1.17% lower sales and 2.10% lower inventories in December 2025 than in December 2024. The inventory-to-sales ratio declined by 0.02 to 1.93. Inventories therefore fell slightly faster than sales over this comparison.

Food and beverage stores reported 1.13% higher sales and 3.34% higher inventories. Their ratio rose by 0.02 to 0.81. In this category, inventory grew faster than sales. This gives a retail report a useful distinction that sales growth alone would miss.

The ratio divides end-of-month inventories by one month of sales. It is not annual inventory turnover, and the different ratios do not establish which category is more profitable or efficiently managed. Sales are a flow; inventories are a stock. Both dollar measures are nominal, so seasonal adjustment does not remove price changes.

Add context to a retail analysis

The retail collection connects this history with consumer prices, payroll employment and county employer establishments. Those products answer related questions with different populations and classifications. CPI item categories do not directly match retail business categories, and national sales cannot be allocated to counties using establishment shares.

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, or load your own CSV of group codes. Keep identifiers as text. The unique observation key is series_id + month.

groups.csv lists the original business labels and identifies available measures. Sales has 64 unadjusted categories and 38 adjusted categories. Inventories and inventory/sales ratios each have nine categories in both forms. For another sales category, a sales-only comparison may be the appropriate task.

series.csv and coverage.csv show reported periods and missing-value counts. A suppressed estimate has availability=source_suppressed; a source unavailable value has availability=source_not_available. Both have blank numeric values and retained original markers. Neither means zero. annual_sales.csv retains the source’s unadjusted annual totals rather than calculating a new total from incomplete monthly data.

Categories and totals overlap. Census publishes both department-store codes 4522 and 45221; retain the selected series rather than adding or silently deduplicating them. Nonstore retail is not a count of all e-commerce. The published population is businesses with paid employees, so do not splice older benchmarks that included nonemployers without reviewing their definitions.

Sources and versions

Source: Census MRTS 2026 annual-revision workbooks, released September 28, 2026 and captured November 7, 2026 UTC. The edition contains January 1992–December 2025 as revised in those workbooks, using 2017 NAICS. Partial 2026 is excluded. This is one retained source edition, not a sequence of original monthly-release vintages.

The annual-revision introduction and explanatory material describe coverage, revisions and source markers. Census provides the 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 7, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.