Compare county housing affordability in Python

Compare renter housing-cost burdens across counties, then examine the same income bracket to understand what an overall percentage can hide.

Compare housing burdens within an income group

Suppose you are preparing a housing needs brief for Durham, Robeson and Wake counties in North Carolina. You want to compare how many renter households spend at least 30% of their income on housing, then examine renters in the same income bracket. The county summary supplies the overall picture; the income table provides the second comparison without another Census extraction.

The optional input.csv contains fictional research labels paired with real county FIPS codes. Those same records appear in the markets list in the Python code below. Only the labels are invented; all reference values are unchanged selections from the paid product.

Download the product samples

Save both files in your working folder. county_housing.csv includes these three counties with all 64 summary fields. income_burden.csv contains their complete 30 income-group records: five positive-income brackets for renters and five for owners per county. The example selects renters earning $20,000–$34,999 before joining.

The full $29 edition covers 3,222 counties and equivalents, including Puerto Rico. Its five CSV tables include county summaries, tenure and mortgage cohorts, income-group detail, original source cells and source-row accounting. Inspect all fields and coverage.

Code example

The example reads FIPS identifiers as text, checks the selected tables for duplicate keys, and adds overall and income-specific cost-burden measures. The results list remains available in your notebook. Printed margins of error are approximate 90% MOEs in percentage points.

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
"""Run directly or paste into a notebook after extracting the product or samples."""
import csv
from pathlib import Path

# Fictional research labels, paired with real county FIPS codes.
markets = [
    {'market': 'Durham research', 'county_fips': '37063'},
    {'market': 'Robeson research', 'county_fips': '37155'},
    {'market': 'Wake research', 'county_fips': '37183'},
]
folder = Path('.')  # Folder containing product files or the guide samples.
with (folder/'county_housing.csv').open(newline='', encoding='utf-8-sig') as file:
    county_rows = list(csv.DictReader(file))
counties = {r['county_fips']: r for r in county_rows}
if len(counties) != len(county_rows):
    raise ValueError('Duplicate county keys')
with (folder/'income_burden.csv').open(newline='', encoding='utf-8-sig') as file:
    selected = [r for r in csv.DictReader(file)
                if r['tenure'] == 'renter' and r['income_band'] == '20000_34999']
income = {r['county_fips']: r for r in selected}
if len(income) != len(selected):
    raise ValueError('Duplicate county/income group keys')

def percentage(value, moe, status):
    if value == '':
        return f'unavailable ({status})'
    uncertainty = f' ± {float(moe):.1f} percentage points' if moe else '; MOE unavailable'
    return f'{float(value):.1f}%{uncertainty}'

results = []
for market in markets:
    key = market['county_fips']
    if key not in counties or key not in income:
        raise ValueError(f'County {key} is absent from the reference')
    county, group = counties[key], income[key]
    result = {**market, 'county_name': county['county_name'],
        'renter_burdened_units': county['renter_burdened_30plus_units'],
        'renter_eligible_units': county['renter_eligible_units'],
        'renter_burdened_pct': county['renter_burdened_30plus_pct'],
        'renter_pct_moe_90': county['renter_burdened_30plus_pct_moe_90'],
        'renter_pct_status': county['renter_burdened_30plus_pct_status'],
        'income_group_units': group['income_group_units'],
        'income_group_burdened_pct': group['burdened_30plus_pct'],
        'income_group_pct_moe_90': group['burdened_30plus_pct_moe_90'],
        'income_group_pct_status': group['burdened_30plus_pct_status']}
    results.append(result)
    count = f"{int(result['renter_burdened_units']):,}" if result['renter_burdened_units'] else 'unavailable'
    print(f"{result['market']} | {key} | {result['county_name']}")
    print(f"  Renters spending at least 30% of income: {count} units; "
          + percentage(result['renter_burdened_pct'], result['renter_pct_moe_90'], result['renter_pct_status']))
    print('  Among renters with $20,000–$34,999 income: '
          + percentage(result['income_group_burdened_pct'], result['income_group_pct_moe_90'], result['income_group_pct_status']))

Analysis of the output

Durham research | 37063 | Durham County, North Carolina
  Renters spending at least 30% of income: 29,135 units; 48.4% ± 2.3 percentage points
  Among renters with $20,000–$34,999 income: 94.2% ± 4.2 percentage points
Robeson research | 37155 | Robeson County, North Carolina
  Renters spending at least 30% of income: 5,600 units; 48.2% ± 2.6 percentage points
  Among renters with $20,000–$34,999 income: 65.6% ± 7.4 percentage points
Wake research | 37183 | Wake County, North Carolina
  Renters spending at least 30% of income: 76,915 units; 48.3% ± 1.3 percentage points
  Among renters with $20,000–$34,999 income: 94.7% ± 1.3 percentage points

The overall renter burden shares are about 48% in all three counties. Their scale differs substantially: the estimated number of renter-occupied units spending at least 30% of income on housing is 29,135 in Durham, 5,600 in Robeson and 76,915 in Wake. A regional brief can use the percentage to describe prevalence and the count to describe the size of the affected group.

Within the $20,000–$34,999 income bracket, the estimates are 94.2% in Durham, 65.6% in Robeson and 94.7% in Wake. The similar overall percentages therefore conceal a different pattern for households in the same income range. This is a descriptive comparison, not a test of statistical significance or evidence about what caused the differences.

The overall percentage uses renter-occupied units with a computed housing-cost ratio as its denominator. Durham has 60,194 such units; Robeson has 11,627 and Wake has 159,290. The separate renter_not_computed_units field keeps the remaining source category visible. It is not counted as either burdened or unburdened. In the income table, the denominator is the count within the selected positive-income bracket.

Housing burden here means costs of at least 30% of household income. The product also supplies severe burden at 50% or more, which is a subset of the 30%+ count. These are estimates of occupied housing units, not individual people. For renters, the source measure is gross rent; for owners it is selected monthly owner costs.

Using the full dataset

Extract the purchased ZIP and replace the samples with the complete files of the same names. Replace markets with your own county list, or read a CSV with market and county_fips columns:

with open("my_counties.csv", newline="", encoding="utf-8-sig") as file:
    markets = list(csv.DictReader(file))

To study a different income group, change income_band in the filter and update the printed label. Available bands are under_20000, 20000_34999, 35000_49999, 50000_74999 and 75000_plus. The lowest bracket covers positive income only. Zero or negative income and no-cash-rent cases are separately retained in the source cells. To compare owners, select owner and use the corresponding owner_ summary fields.

cost_burden.csv adds comparisons for owners with and without mortgages, with source-variable formulas beside each count. The all-owner cohort overlaps those subgroups; do not sum all three. Similarly, filter the income table before joining a one-row-per-county input, or retain its full county/tenure/income key when working with multiple groups.

Published count MOEs are retained. Derived count MOEs use the square root of summed squared component MOEs. Derived shares use Census’s approximate subset-percentage formula, with its ratio-formula fallback where needed. Method/status fields identify the calculation. These approximations do not use covariance-aware replicate estimates; consult the source guidance before making formal comparisons. Blank estimates and unavailable MOEs have explicit statuses; they are not zeros.

The ACS County Demographic Profile adds median rent, home value and broader household context for the same survey period. The County Income & Poverty Reference provides separate annual estimates, and the County Population & Migration History adds population change. Check periods, geographic vintages and populations before combining them.

Sources and versions

Source: U.S. Census Bureau, 2020–2024 American Community Survey five-year detailed tables B25070, B25091 and B25106, released January 29, 2026. Estimates use 2024 county geography and income brackets in 2024 inflation-adjusted dollars. They describe a five-year survey period, not current asking rents or a single-year 2024 observation.

ACD captured the original responses October 18, 2026 UTC and packaged this preparation 2026-10-18. Read the source and preparation record and Census guidance for derived margins of error for the calculation basis. This is the first ACD edition of these inputs; it does not claim changes against an earlier release.

The pipeline checks source partitions and county keys, accounts for every captured row, and independently compares delivered source values and derived measures with the retained original JSON. These checks verify our preparation, not the absence of survey error.

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