Look up postal ZIP counties and address shares in Python
Find all county relationships for postal ZIP codes and compare residential with business address shares.
Connect postal ZIP records with counties
A service-area analyst starts with postal ZIP codes in Cary and Apex, North Carolina, and wants to add county context. The crosswalk identifies every county represented in each ZIP and shows how residential and business addresses are distributed between them.
Download zip_county.csv below. This genuine subset contains every county relationship for ZIPs 27513, 27519 and 27523, with all 15 columns from the paid file. The same three ZIP selections appear in the Python code below. There are no invented addresses or customer records.
The full $29 edition contains 54,561 relationships for 39,475 postal ZIPs, plus coverage for all 39,484 ZIPs in the original HUD file and nine source-geography exceptions. Six CSV tables include optional largest-share county selections and ratio checks. Inspect the full Q2 2026 download.
Code example
Save zip_county.csv in your working directory. This code runs in a notebook cell, IPython or a Python script using only the standard library. It reads identifiers as text and converts address shares to percentages for display.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
import csv
from decimal import Decimal
# Genuine postal ZIP selections: Cary and Apex, North Carolina.
zip_codes = {"27513", "27519", "27523"}
with open("zip_county.csv", newline="", encoding="utf-8") as file:
relationships = [row for row in csv.DictReader(file)
if row["zip_code"] in zip_codes]
results = []
for row in relationships:
result = {
"zip_code": row["zip_code"],
"county_fips": row["county_fips"],
"county_name": row["county_name"],
"residential_percent": f"{Decimal(row['residential_ratio']) * 100:.2f}",
"business_percent": f"{Decimal(row['business_ratio']) * 100:.2f}",
}
results.append(result)
print(f"{result['zip_code']} | {result['county_fips']} | "
f"{result['county_name']}: residential {result['residential_percent']}%, "
f"business {result['business_percent']}%")
Analysis of the output
27513 | 37183 | Wake County: residential 100.00%, business 100.00%
27519 | 37037 | Chatham County: residential 6.84%, business 0.21%
27519 | 37183 | Wake County: residential 93.16%, business 99.79%
27523 | 37037 | Chatham County: residential 13.50%, business 18.31%
27523 | 37183 | Wake County: residential 86.50%, business 81.69%
ZIP 27513 maps entirely to Wake County in this source. ZIP 27519 has relationships with both Wake and Chatham counties: 6.84% of its residential addresses are in Chatham, compared with 0.21% of its business addresses. ZIP 27523 also spans these counties, with a different distribution.
The result gives the analyst county names and five-digit identifiers for a subsequent join to county reference data. It also makes the choice of address type visible. Residential and business weights answer different allocation questions; neither measures the share of population or land.
If you allocate a ZIP-level customer total using a residential share, you assume those customers follow the source’s residential-address distribution. The crosswalk does not establish that assumption. An individual address’s county requires an address-level lookup or geocoding. Keep all relationships when exploring coverage; simply summing a customer amount repeated by a many-to-many join would double count.
Using the full dataset
Extract the purchased ZIP and replace the sample with its full zip_county.csv; this code runs unchanged. Replace zip_codes with your own five-character ZIP values, or load that column from your CSV as text. The main key is zip_code plus county_fips.
For a deliberate single-county selection, use largest_share_county.csv and filter address_type first. ACD selects the largest positive share, breaking ties by the lowest county FIPS and recording the tie count. All-zero address categories have no selected county. This convenience rule is not an official assignment of individual addresses.
When a ZIP is absent from the main table, check zip_coverage.csv. Nine source rows—including ZIP 77352—have a two-character GEOID instead of a five-digit county code; they remain in source_exceptions.csv with their original weights. No replacement county is guessed. ZIPs absent from the coverage file were absent from the retained HUD source; their individual exclusion reason is unknown.
For Census ZCTA inputs and land-area intersections, use the separate ZCTA-to-county crosswalk. Postal ZIP codes and Census ZCTAs are different concepts. The postal and county geography collection explains the available starting points and county companions.
Sources and versions
The original HUD-USPS ZIP-to-county file is free with a HUD User login. This edition retains Q2 2026, the latest quarter offered at capture on November 12, 2026 UTC. June 30 is the quarter-end observation date, not a claimed release date. County labels come from the separately retained Census 2026 reference, matched by exact code without changing HUD relationships.
HUD excludes PO-box-only ZIPs and some ungeocoded records. Source geography includes Connecticut planning regions and territories; check county-vintage compatibility before joining other datasets. We retain all original decimal ratios, including tiny sum differences, without normalization. Postal preferred city/state is an address name, not an administrative boundary.
ACD adds labeled CSVs, selections, exception and coverage reports, dictionaries and this verified example. The source and preparation record distinguishes this fixed source quarter from our processing revision. Processing improvements and documented publisher corrections to the purchased edition are included; later quarterly editions may be sold separately.
Example checked November 12, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.