ZIP Code to Census Tract in Python: compare both directions

Look up postal ZIP/tract relationships and compare original address shares in the two directions.

Connect postal ZIP codes with Census tracts

A service-area analyst has postal ZIP records and wants to connect them with tract-level geography. The HUD-USPS crosswalk supplies every observed ZIP/tract relationship and the share of residential, business, other and total addresses in each part.

Download the two genuine product subsets below. zip_tract.csv contains both tract relationships for ZIP 27507. tract_zip.csv contains all three ZIP relationships for tract 37077970101 in Granville County, North Carolina. Both retain all 18 columns from the paid tables. The same ZIP and tract selections appear in the Python code below; no addresses or customer records are invented.

The full $29 edition contains 189,428 relationships in each original direction, covering 39,350 postal ZIPs and 84,932 tracts. Seven CSV tables include county context, optional largest-share selections and source coverage checks. Inspect the full Q2 2026 download.

Code example

Save both CSVs in your working directory. Run this code in a notebook cell, IPython or a Python script. It uses the standard library, reads identifiers as text, and formats the source ratios as percentages.

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
import csv
from decimal import Decimal

# Genuine selections: ZIP 27507 and a tract it overlaps in Granville County, NC.
selections = [
    ("zip_tract.csv", "zip_code", "27507", "tract_geoid", "of ZIP addresses"),
    ("tract_zip.csv", "tract_geoid", "37077970101", "zip_code", "of tract addresses"),
]
results = []
for filename, origin_field, origin, destination_field, denominator in selections:
    with open(filename, newline="", encoding="utf-8") as file:
        relationships = [row for row in csv.DictReader(file)
                         if row[origin_field] == origin]
    for row in relationships:
        result = {
            "direction": row["direction"],
            "origin": origin,
            "destination": row[destination_field],
            "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"{origin} → {result['destination']} | {result['county_name']} | "
              f"residential {result['residential_percent']}%, "
              f"business {result['business_percent']}% {denominator}")

Analysis of the output

27507 → 37077970101 | Granville County | residential 86.74%, business 75.00% of ZIP addresses
27507 → 37181960200 | Vance County | residential 13.26%, business 25.00% of ZIP addresses
37077970101 → 27507 | Granville County | residential 33.31%, business 8.96% of tract addresses
37077970101 → 27565 | Granville County | residential 66.69%, business 89.55% of tract addresses
37077970101 → 27582 | Granville County | residential 0.00%, business 1.49% of tract addresses

ZIP 27507 crosses two tracts: 86.74% of its residential addresses are in tract 37077970101 in Granville County, and 13.26% are in tract 37181960200 in Vance County. The county names and identifiers provide context for a subsequent geographic join.

Looking in the other direction answers a different question. Only 33.31% of residential addresses in tract 37077970101 belong to ZIP 27507; most belong to ZIP 27565. The first percentage uses the ZIP as its denominator, while the second uses the tract. Both come from their own original HUD table. Reversing columns or taking a reciprocal would not produce the correct reverse weights.

The source also reports a ZIP relationship with zero residential share but a positive business share. Keeping all relationships makes that distinction visible. Address shares are not population, household or customer shares. Allocating a customer total requires an explicit assumption that customers follow the chosen address distribution; an individual address’s tract still requires geocoding.

Using the full dataset

Extract the purchased ZIP and replace the two sample CSVs with the full files; the code runs unchanged. Edit selections for your own five-character ZIPs or eleven-character tract GEOIDs. For a batch join, read your input keys as text and choose the correct direction before joining. Preserve every match, and do not sum an input total repeated across multiple relationships.

If you deliberately need one destination, filter largest_share.csv by direction and address_type. It selects the largest positive share, breaking ties by lowest destination code and recording the tie count. An all-zero category has no selection. This is a documented convenience rule, not an official address assignment.

origin_coverage.csv accounts for every source origin in each direction; ratio_checks.csv retains original sums without normalization. tract_reference.csv supplies county context and explicitly marks 74 territorial tracts outside the Census gazetteer’s coverage. Those tracts remain in the crosswalk.

The postal and Census geography collection helps choose between this tract crosswalk, the postal ZIP-to-county crosswalk, and Census ZCTA land intersections. Postal ZIPs and Census ZCTAs are different inputs.

Sources and versions

The original HUD-USPS crosswalk files are free with a HUD User login. This edition retains Q2 2026 ZIP–Tract and Tract–ZIP workbooks, the latest quarter offered when captured November 12, 2026 UTC. June 30 is quarter end, not a verified publication date.

Census 2026 county and tract references check original identifiers without changing geography. The actual HUD file uses Connecticut’s nine planning-region county prefixes; review geographic vintages before joining historical data. HUD omits PO-box-only ZIPs and some ungeocoded addresses. An absent origin’s individual reason is unknown. No population counts, address counts or boundary polygons are included.

ACD adds documented CSVs, county labels, separate directional selections and checks, and this tested example. The source and preparation record separates the fixed source quarter from ACD processing. Processing improvements and documented publisher corrections to this purchased edition are included; later source quarters 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.