Compare house-price appreciation across ZIP territories in Python

Compare genuine annual FHFA house-price indexes for fictional service territories over common years, retaining missing endpoints and geographic limitations.

Compare house-price appreciation across service territories

A remodeling company has customer ZIPs and wants to compare housing-market trends across its service territories. FHFA’s annual indexes supply a consistent price-appreciation measure. The prepared history lets the company compare the same years, then consider those results alongside its own inquiries and sales.

input.csv contains three fictional territory assignments, A, B and C, with real ZIP codes. The same records appear in the territories list in the Python code below. These assignments illustrate the company’s input; all price-index values come from the genuine FHFA source.

Download zip_history.csv below. It is a genuine subset of the paid table: the complete published history for ZIPs 01001, 27511 and 27513, with all 20 fields unchanged. The code selects 2020 and 2025. The input CSV is optional because its records are also in the code.

The full $29 edition includes 689,533 annual records for 19,024 source ZIPs, prepared one-, five- and ten-year comparisons, and coverage tables. History spans 1975–2025 overall, with differing starts and gaps; 15,772 ZIPs report a 2025 index. Inspect the complete download.

Source: FHFA House Price Index® (annual developmental All-Transactions, nominal, not seasonally adjusted). This product uses FHFA data but is neither endorsed nor certified by FHFA.

Code example

Place the sample in your working directory and run this code in a notebook, IPython or a script. It uses Python’s standard library, keeps ZIP codes as text, and reads the file one row at a time. The calculation uses the same index basis within each ZIP.

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
"""Compare genuine price appreciation for fictional service territories."""
import csv
from decimal import Decimal

# Fictional business inputs, also supplied in input.csv on the guide page.
territories = [
    {"territory": "A", "zip_code": "01001"},
    {"territory": "B", "zip_code": "27511"},
    {"territory": "C", "zip_code": "27513"},
]
start_year, end_year = "2020", "2025"
wanted = {item["zip_code"] for item in territories}
selected = {}
with open("zip_history.csv", newline="", encoding="utf-8") as file:
    for row in csv.DictReader(file):
        key = row["zip_code"], row["year"]
        if key[0] not in wanted or key[1] not in {start_year, end_year}:
            continue
        if key in selected:
            raise ValueError(f"Duplicate ZIP-year: {key}")
        if (row["index_type"], row["adjustment"], row["price_basis"]) != (
            "annual_developmental_all_transactions", "NSA", "nominal"
        ):
            raise ValueError(f"Incompatible index: {key}")
        selected[key] = row

results = []
print(f"Nominal house-price appreciation, {start_year} to {end_year}")
for item in territories:
    code = item["zip_code"]
    a, b = selected.get((code, start_year)), selected.get((code, end_year))
    available = all(row and row["hpi_first_base_status"] == "reported" for row in (a, b))
    change = ""
    if available:
        change = f'{(Decimal(b["hpi_first_base"]) / Decimal(a["hpi_first_base"]) - 1) * 100:.2f}'
    results.append(dict(territory=item["territory"], zip_code=code,
                        start_year=start_year, end_year=end_year, change_pct=change,
                        match_status="available" if available else "endpoint_unavailable"))
    display = change + "%" if available else "Endpoint unavailable; see zip_coverage.csv"
    print(f'Territory {item["territory"]} | ZIP {code} | {display}')
print("These are changes within each ZIP, not dollar home prices or a forecast of remodeling demand.")

Analysis of the output

Nominal house-price appreciation, 2020 to 2025
Territory A | ZIP 01001 | 41.91%
Territory B | ZIP 27511 | 60.32%
Territory C | ZIP 27513 | 58.77%
These are changes within each ZIP, not dollar home prices or a forecast of remodeling demand.

From 2020 to 2025, ZIP 27511’s index implies 60.32% nominal appreciation, compared with 58.77% for 27513 and 41.91% for 01001. The company can put this comparison beside its own territory activity to identify questions worth investigating. Appreciation alone does not establish remodeling demand, homeowner equity or future sales.

The percentages compare changes within each ZIP over common years. They do not show which territory has more expensive homes. Each first-base index starts at 100 in a different potential year; even an index with a common base is not a dollar home-price estimate.

These annual developmental indexes use a filtered single-family sample of conventional conforming mortgages purchased or securitized by Fannie Mae or Freddie Mac, including refinance appraisals. They are not median sale prices, year-end values or estimates covering every property or transaction. The source methodology excludes condominiums, cooperatives, multi-unit properties and planned unit developments.

Using the full dataset

Extract your purchase and replace the sample with the full zip_history.csv; the code runs unchanged. Change start_year and end_year for another comparison. Replace territories with your own records read using csv.DictReader, retaining the territory and zip_code columns or adapting their names. A ZIP+4 input can be explicitly reduced to its first five digits; this product does not estimate ZIP+4-level statistics.

For the supplied comparison periods, use period_changes.csv directly. It includes every source ZIP for 2015–2025, 2020–2025 and 2024–2025, with both endpoints and a comparison status. Of its 57,072 records, 10,971 lack an endpoint and retain a blank change. These percentages are cumulative, not annualized.

zip_coverage.csv identifies actual starting years, gaps and 2025 availability. annual_coverage.csv shows how coverage varies over time. The history preserves 19,368 source rows without a first-base index. Missing cells and absent ZIP-years are different; neither means zero growth. The code retains unavailable selected endpoints with endpoint_unavailable.

The source’s published annual percentage change is preserved separately. A ratio of rounded indexes may differ slightly; comparison_checks.csv documents the rounding relationship without changing the source. These arithmetic bounds are not confidence intervals. No per-index transaction counts or statistical uncertainty are supplied.

Each CSV fits below Excel’s worksheet row limit. Import through Data > From Text/CSV and set ZIP columns to text before loading, especially for leading-zero ZIPs. Large files may load slowly. Filter periods before joining; do not sum index levels across ZIPs.

FHFA assigns past transactions to each property’s current USPS location in this source edition. This is not a reconstruction of ZIP boundaries in each historical year. Our ZIP-area housing stock uses Census ZCTAs and a five-year survey period; the ZIP business history uses annual postal geography. Review those differences before combining them. The county price history is an alternative for county-keyed work, not a required companion. Compare ZIP and geography products.

Sources and versions

The FHFA annual ZIP5 workbook is dated March 31, 2026 and was retained November 28, 2026 UTC. Observations end in 2025. This is one fixed edition of revised history, not a collection of each year’s original publication.

FHFA supplies the source free. ACD adds CSV preparation, text identifiers, endpoint comparisons, coverage and arithmetic checks, dictionaries and this verified example. Read the local-index methodology and geography FAQ and the source and preparation record.

Processing improvements and genuine publisher-error corrections to the purchased edition are included. Routine re-estimation and new periods may be separately purchased editions. This is not a subscription.

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