Compare residential mobility across ZIP areas in Python
Compare genuine residential mobility estimates for fictional ZIP-coded territories, retaining age/tenure definitions, uncertainty and unmatched rows.
Compare residential mobility across ZIP areas
A business with ZIP-coded service territories wants to understand how residential mobility differs across its markets. This reference adds the share of residents living in a different home one year earlier, with separate measures for people in owner- and renter-occupied households.
input.csv contains four fictional service territories. The same records appear in the territories list in the Python code below. The labels and ZIP selections demonstrate the join; the Census estimates are genuine.
Save zcta_mobility.csv below in your working directory. This is a smaller version of the paid profile: complete records for ZCTAs 01001, 10001 and 27513, with all 68 fields unchanged. The optional input CSV is already embedded in the code.
The full $29 edition provides 33,772 ZCTA profiles and mobility by age and tenure, plus householder move-in periods, original source cells, uncertainty and coverage in eight data tables.
Matching a postal ZIP to the same-code Census ZCTA provides approximate area context. ZIP+4 uses five digits. A match does not validate an address or provide nine-digit estimates.
Code example
This uses Python’s standard library and runs in a notebook, IPython or a script. It keeps every input row and prints three mobility shares with approximate 90% margins of error. Owner and renter measures count residents age one and older in households, not households themselves.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
"""Compare residential mobility in fictional service territories. Paste into a notebook or run as a script."""
import csv
import re
from collections import Counter
# These fictional service territories also appear in example_input.csv. They
# illustrate a ZIP join, not real customers or evidence of demand.
territories = [
{'territory': 'A', 'postal_zip': '01001'},
{'territory': 'B', 'postal_zip': '27513-1234'},
{'territory': 'C', 'postal_zip': '10001'},
{'territory': 'D', 'postal_zip': '00000'},
]
def normalize_zip(value):
if value is None or isinstance(value, str) and not value.strip():
return '', '', 'missing_input'
if not isinstance(value, str): # Never guess lost leading zeros.
return '', '', 'invalid_format'
code = value.strip()
if re.fullmatch(r'[0-9]{5}', code):
return code, 'zip5_as_supplied', ''
if re.fullmatch(r'[0-9]{9}|[0-9]{5}-[0-9]{4}', code):
return code[:5], 'zip_plus4_to_zip5', ''
return '', '', 'invalid_format'
def load_profiles(filename):
profiles = {}
with open(filename, encoding='utf-8', newline='') as source:
for row in csv.DictReader(source):
code = row['zcta_code']
if not re.fullmatch(r'[0-9]{5}', code) or code in profiles:
raise ValueError('The reference must have one row per five-digit ZCTA.')
profiles[code] = row
return profiles
def enrich_territories(input_rows, profiles):
output = []
for order in input_rows:
code, method, problem = normalize_zip(order['postal_zip'])
area = profiles.get(code)
status = problem or ('matched_zcta_code' if area is not None else 'no_zcta_match')
row = {**order, 'zip5': code, 'normalization_method': method,
'match_resolution': 'zip5' if code else '', 'match_status': status,
'matched_zcta_code': code if area is not None else ''}
for field in [name + suffix for name in ('different_home_pct', 'owner_residents_different_home_pct', 'renter_residents_different_home_pct')
for suffix in ('', '_moe_90', '_status', '_moe_status')]:
row['area_' + field] = area[field] if area is not None else ''
output.append(row)
return output
profiles = load_profiles('zcta_mobility.csv')
results = enrich_territories(territories, profiles)
assert len(results) == len(territories) # A many-to-one join must preserve input rows.
def display_share(row, metric):
stem = 'area_' + metric + '_pct'
if not row[stem]:
return row[stem + '_status']
margin = row[stem + '_moe_90']
uncertainty = f"± {float(margin):.1f} pp" if margin else row[stem + '_moe_status']
return f"{float(row[stem]):.1f}% {uncertainty}"
for row in results:
context = row['match_status']
if context == 'matched_zcta_code':
context = (f"ZCTA {row['matched_zcta_code']} | Different home 1 year ago {display_share(row, 'different_home')} | "
f"owner-household residents {display_share(row, 'owner_residents_different_home')} | "
f"renter-household residents {display_share(row, 'renter_residents_different_home')}")
print(f"{row['territory']} | ZIP {row['postal_zip']} | {context}")
print('Input match coverage:', dict(Counter(row['match_status'] for row in results)))
# Shares describe people age 1 or over, with separate owner/renter household
# denominators. MOEs are approximate 90% margins in percentage points. These
# five-year estimates compare residence at interview with one year earlier;
# they do not identify individual movers or forecast future moves.
Analysis of the output
A | ZIP 01001 | ZCTA 01001 | Different home 1 year ago 9.4% ± 2.7 pp | owner-household residents 7.9% ± 3.1 pp | renter-household residents 16.4% ± 7.5 pp
B | ZIP 27513-1234 | ZCTA 27513 | Different home 1 year ago 16.0% ± 3.6 pp | owner-household residents 7.5% ± 3.4 pp | renter-household residents 34.5% ± 7.9 pp
C | ZIP 10001 | ZCTA 10001 | Different home 1 year ago 20.0% ± 1.9 pp | owner-household residents 4.8% ± 3.3 pp | renter-household residents 17.6% ± 2.3 pp
D | ZIP 00000 | no_zcta_match
Input match coverage: {'matched_zcta_code': 3, 'no_zcta_match': 1}
Territories A and B have similar point estimates for residents of owner-occupied households who lived in a different home one year earlier: 7.9% and 7.5%. Their renter-household residents have more different estimates: 16.4% in A and 34.5% in B. Separating the two populations adds context that an overall mobility measure would hide.
A business could use this comparison to frame local research about customer turnover or compare markets alongside its own retention data. The estimates do not identify likely customers, predict moves or explain why residents moved. Keep the margins beside the point estimates; this example does not test statistical significance.
The overall measure includes residents age one and older in group quarters. Owner and renter measures exclude group quarters. That difference helps explain why Territory C’s overall mobility share can exceed both household measures. The current tenure identifies where people live now, not whether they previously rented or owned.
“Different home one year ago” includes moves within the same county or municipio, including moves that may stay in the same ZCTA. It is not a count of arrivals to the ZIP area, departures, all moving events or net migration. People who moved away and returned to the same home are in the same-home category.
Territory B retains its original ZIP+4 and records its five-digit match. Territory D remains with no_zcta_match because 00000 is absent from the reference. Missing estimates and zero denominators retain explicit statuses. Sampling margins do not quantify ZIP/ZCTA boundary mismatch.
Using the full dataset
After purchase, replace the sample with the full zcta_mobility.csv. Replace territories with your own CSV records containing territory and postal_zip, importing ZIPs as text. The same code works with both files.
The profile provides six counts and nine shares with uncertainty and status fields. Detail files separate five mobility categories across 15 age groups and owner/renter household populations. Filter categories before joining these tables, which contain multiple records per area. Age-specific shares use all residents of the selected age group; tenure shares use people in the selected current tenure.
householder_move_in.csv answers a different question: when did the householder most recently move into the occupied housing unit? Its six periods run from 2023 or later to 1989 or earlier, separately for owner and renter units. Those counts measure housing units, not people or all household members’ move dates. The profile also provides shares with householders who moved in from 2020 onward or before 2000.
The ZIP housing-stock reference adds housing types and construction periods. The ZIP housing-cost reference adds affordability context. They use the same ACS period and ZCTA geography but remain optional separate purchases. Area associations do not identify which individuals moved or why. Repeated customer ZIPs repeat area counts, so do not sum joined counts as distinct residents.
Sources and versions
U.S. Census Bureau, 2020–2024 ACS five-year Detailed Tables B07001/B07001PR, B07013/B07013PR and B25038, released January 29, 2026. These are pooled five-year estimates of residence one year before interview, not a 2024 annual total or cumulative five-year moves. The 2024 geographic reference uses 2020 ZCTA delineations and includes Puerto Rico.
Mobility by age · Mobility by tenure · Householder move-in periods · Source and preparation record.
Puerto Rico uses its own mobility categories and reference geography. Published count margins remain available; combined counts and percentages use documented Census uncertainty approximations. Processing improvements and genuine publisher corrections to this purchased edition are included; future source editions may be sold separately.