Compare ZIP-area commuting and vehicle availability in Python
Join fictional service territories to genuine Census resident work patterns and household vehicle shares, retaining uncertainty and unmatched ZIPs.
Compare commuting patterns across service areas
A local service business has a list of postal ZIP codes and wants to compare the areas it serves. This reference adds resident work-from-home shares, travel times and household vehicle availability. Those measures can inform an area profile before investigating service hours, delivery options or access needs.
input.csv contains four fictional service territories. The same records appear in the territories list in the Python code below. The territory names and ZIP selections illustrate the join; the Census estimates are genuine.
Download zcta_commuting.csv below and save it in your working directory. It is a smaller version of the paid summary file: complete profiles for ZCTAs 01001, 10001 and 27513, with all 67 fields unchanged. The optional input CSV is also embedded in the code.
The full $29 edition covers 33,772 Census ZCTAs in seven CSVs, including nine commuting/home-work modes, twelve travel-time bins and vehicle availability by household size. These are 2020–2024 ACS five-year estimates.
A postal ZIP matched to the identically numbered Census ZCTA supplies approximate area context. ZIP+4 uses only its first five digits. These are residence-based estimates, not workplace employment, daytime foot traffic or attributes of individual customers.
Code example
This uses Python’s standard library and runs in a notebook, IPython or a script. It keeps ZIPs as text, preserves unmatched territories and prints three area shares with approximate 90% margins of error 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.
"""Compare resident commuting patterns 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 ('worked_from_home_pct', 'commute_30plus_pct', 'no_vehicle_households_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_commuting.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']} | home workers {display_share(row, 'worked_from_home')} | "
f"commuters travelling 30+ min {display_share(row, 'commute_30plus')} | "
f"households without vehicles {display_share(row, 'no_vehicle_households')}")
print(f"{row['territory']} | ZIP {row['postal_zip']} | {context}")
print('Input match coverage:', dict(Counter(row['match_status'] for row in results)))
# Home-work shares use resident workers age 16+. Travel-time shares exclude
# home workers. Vehicle shares use households. MOEs are approximate 90%
# percentage-point margins. ZIP+4 uses only five digits. These area estimates
# do not establish an individual's behavior or a workplace's daytime population.
Analysis of the output
A | ZIP 01001 | ZCTA 01001 | home workers 11.2% ± 3.1 pp | commuters travelling 30+ min 23.0% ± 4.2 pp | households without vehicles 9.4% ± 3.6 pp
B | ZIP 27513-1234 | ZCTA 27513 | home workers 36.2% ± 3.4 pp | commuters travelling 30+ min 21.3% ± 2.9 pp | households without vehicles 2.4% ± 1.0 pp
C | ZIP 10001 | ZCTA 10001 | home workers 26.0% ± 3.7 pp | commuters travelling 30+ min 44.9% ± 4.5 pp | households without vehicles 83.1% ± 3.0 pp
D | ZIP 00000 | no_zcta_match
Input match coverage: {'matched_zcta_code': 3, 'no_zcta_match': 1}
Territory B’s original ZIP+4 is retained, while its first five digits match ZCTA 27513. An estimated 36.2% of resident workers age 16 and over worked from home, with an approximate margin of 3.4 percentage points. Among workers who commuted, 21.3% had a one-way trip of at least 30 minutes. Separately, 2.4% of households had no vehicle available.
ZCTA 10001 has a much larger estimated share of households without vehicles, 83.1%. That is useful context when comparing service areas, but vehicle availability alone does not establish delivery demand or unmet transport need. Work-from-home estimates describe the survey’s usual means of getting to work; they do not count everyone who sometimes works remotely.
The three percentages describe different populations. Home-working uses all resident workers age 16 and over; travel time excludes home workers; vehicle availability uses households. Do not combine them into a score without deciding what that score would mean. Keep margins beside comparisons; this example does not test statistical significance.
Territory D stays in the results with no_zcta_match because 00000 is absent from this reference. A matched area can also have an unavailable measure or no denominator; the code prints that status rather than a false zero. Census sampling margins do not measure postal-ZIP/ZCTA boundary differences.
Using the full dataset
After purchase, replace the sample with the full zcta_commuting.csv. Replace territories with your own CSV records containing territory and postal_zip, keeping ZIPs as text. The results list can be written to another CSV. Every input row remains present.
Use commute_modes.csv for original counts and shares for driving alone, carpooling, transit and other modes. travel_time.csv preserves the twelve published bins. vehicle_availability.csv supplies five vehicle categories for all households and four household-size groups.
Filter the detailed category before joining it to customer rows. The all-household vehicle group overlaps the size subgroups; 60-minute-plus commuters are included in the 30-minute-plus share. Do not add overlapping totals or average area percentages. The archive includes all 64 source estimate/MOE pairs per area, annotations, dictionaries, coverage and source accounting.
The ZIP-area demographic profile and ZIP-area housing reference use the same survey period and ZCTA geography. They are optional separate purchases for population, income and housing context. This guide works on its own.
Sources and versions
Source: U.S. Census Bureau, 2020–2024 ACS five-year Detailed Tables B08301, B08303 and B08201, released January 29, 2026. The 2024 ACS geography reference uses 2020 ZCTA delineations and includes Puerto Rico.
Original Census tables · ZCTA definitions · Source and preparation record.
Published count margins are retained. Derived sums and shares use documented Census approximations, with a flagged ratio fallback where required. Same-edition processing improvements and publisher error corrections are included. Future source editions may be sold separately.