Compare new-home sales and unsold inventory in Python

Compare annual sales, completed unsold homes and prices using genuine Census NRS data.

Compare sales with homes still waiting for buyers

A housing analyst wants to know whether unsold new homes are accumulating as completed inventory. Annual sales show how many homes found buyers; December-end inventory shows what remained for sale. Separating completed homes from all unsold homes helps a builder or supplier understand a market that a sales total alone cannot describe.

Download annual.csv below. This is a genuine subset of the purchased table: 12 observations covering U.S. sales, total unsold inventory, completed unsold inventory and median sale price in 2023–2025. All 22 fields are unchanged. The four series and three years are selected in the Python code below; there are no invented observations.

The full $29 edition contains 27,972 monthly observations, 1,323 annual observations and six supporting CSV tables. Sales and inventory include the United States and four Census regions; prices and construction-stage detail are national. Inspect the complete download.

Code example

This standard-library code runs in a notebook cell, IPython or a script. It checks each series’ units, adjustment and period basis, then converts thousands of homes to housing units for display. The completed share uses the same year-end total inventory as its denominator.

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
from pathlib import Path

# annual.csv has identical columns in the free sample and the purchased ZIP.
data_dir = Path('.')
years = (2023, 2024, 2025)
series = {
    'market:sold:US:total:annual:NSA': ('sold', 'thousands_of_housing_units', 'annual_flow'),
    'market:for_sale:US:total:annual:NSA': ('inventory', 'thousands_of_housing_units', 'year_end_stock'),
    'construction_stage:for_sale:US:completed:annual:NSA': ('completed_inventory', 'thousands_of_housing_units', 'year_end_stock'),
    'market:median_price:US:total:annual:NSA': ('median_price', 'nominal_us_dollars', 'annual_sale_price_statistic'),
}
selected = {}
with (data_dir / 'annual.csv').open(newline='', encoding='utf-8') as file:
    for row in csv.DictReader(file):
        if row['series_id'] not in series or int(row['year']) not in years:
            continue
        label, unit, basis = series[row['series_id']]
        key = (int(row['year']), label)
        if key in selected:
            raise ValueError(f'Duplicate observation: {key}')
        if (row['availability'] != 'reported' or row['unit'] != unit
                or row['period_basis'] != basis or row['frequency'] != 'annual'
                or row['adjustment'] != 'NSA'):
            raise ValueError(f'Unavailable or incompatible observation: {key}')
        selected[key] = Decimal(row['value']) * (1000 if unit == 'thousands_of_housing_units' else 1)

results = []
print('U.S. new single-family homes; inventory is measured at year end.\n')
for year in years:
    labels = ('sold', 'inventory', 'completed_inventory', 'median_price')
    if any((year, label) not in selected for label in labels):
        raise ValueError(f'Missing observations for {year}')
    sold, inventory, completed, price = (selected[year, label] for label in labels)
    if inventory <= 0 or not 0 <= completed <= inventory:
        raise ValueError(f'Invalid inventory denominator or component for {year}')
    share = completed / inventory * 100
    results.append(dict(year=year, houses_sold=int(sold), year_end_inventory=int(inventory),
                        completed_unsold=int(completed), completed_inventory_percent=f'{share:.1f}',
                        median_sale_price=int(price)))
    print(f'{year}: sold {sold:,.0f} | for sale {inventory:,.0f} | completed unsold {completed:,.0f} ({share:.1f}%) | median ${price:,.0f}')

Analysis of the output

U.S. new single-family homes; inventory is measured at year end.

2023: sold 666,000 | for sale 450,000 | completed unsold 87,000 (19.3%) | median $428,600
2024: sold 686,000 | for sale 491,000 | completed unsold 118,000 (24.0%) | median $420,300
2025: sold 678,000 | for sale 475,000 | completed unsold 134,000 (28.2%) | median $417,400

From 2024 to 2025, annual new-home sales fell from 686,000 to 678,000, and total year-end inventory fell from 491,000 to 475,000. Completed homes still for sale moved the other way: from 118,000 to 134,000. Their share of unsold inventory rose from 24.0% to 28.2%.

This gives the analyst a more specific result than “inventory fell.” A larger share of remaining inventory was finished and awaiting a buyer. These are aggregate estimates, not a matched set of individual homes or evidence that the year’s completions failed to sell.

The median sale price fell from $420,300 to $417,400. That is a nominal statistic including land, and it changes with the mix of homes sold. It does not establish that the same home lost value. The displayed changes are not tests of statistical significance.

Using the full dataset

Extract the purchased ZIP and replace the sample with its complete annual.csv; the code runs unchanged. Change years or select other identifiers from series.csv. Check their units, observation basis and reported date range first. Regional prices are not included.

observations.csv contains monthly history. Unadjusted sales are monthly flows, adjusted sales are annualized rates, and inventory is an end-month stock. Do not sum twelve annualized rates or twelve inventory figures into an annual count. The annual inventory used here is measured at December end; annual prices are the publisher’s annual statistics, not averages of monthly prices.

coverage.csv distinguishes reported values from unavailable cells. source_notes.csv and the source coordinates retain context. The market and construction-stage tables repeat some national totals under distinct series identifiers: select one table for a measure rather than summing both.

The audits retain one source discrepancy: May 1994 construction-stage inventory components sum to 295,000 homes, while the published total is 301,000. The difference is recorded in comparison_checks.csv; observations.csv identifies the original workbook cells. This does not affect the 2023–2025 example and is not a confirmed publisher error.

The construction collection adds starts, completions, county permits and spending. The NRS sales universe is new single-family homes built for sale; other construction datasets have broader or different coverage. These files do not allocate national sales to counties or link individual homes across stages.

Sources and versions

Source: Census/HUD New Residential Sales historical workbooks, captured November 10, 2026 UTC. This is revised history through 2025, with source rows beginning in 1963 and later first reported dates for some series. It is not a collection of original monthly vintages. Partial 2026 and seasonal factors remain in retained sources but are excluded from the analytical tables.

Under the Survey of Construction definitions, a sale is a contract or deposit, not a closing; a subsequent cancellation does not revise the original sale. Existing-home resales, homes built for rent, owner-built homes and contractor-built homes on the owner’s land are outside this product’s sales universe.

Census provides the workbooks free. ACD sells preparation, validation, documentation and delivery. Processing improvements and publisher error corrections to this purchased edition are included; future source editions may be separate purchases. Read the source and preparation record.

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