Find county workforce origins in Python
Rank outside residence counties supplying local primary jobs, and put each flow in context with a workplace-job share.
Find the counties supplying a local workforce
You are comparing labor markets for a location brief. A county’s job total tells you how many jobs are based there; residence-to-workplace relationships show where that workforce lives. This example finds the three largest outside residence counties supplying primary jobs in Wake and Durham counties, North Carolina, in 2023.
The optional input.csv contains those two real workplace-county selections. The same codes appear in the counties list in the Python code below. No job counts or county relationships are invented.
Download both sample CSVs into your working folder. county_flows.csv contains every residence-county relationship for the two selected workplace counties, including local jobs. county_summary.csv supplies their full workplace totals. Both are genuine subsets of the paid files with all product columns unchanged. The $29 full download covers available 2023 primary-job relationships for workplaces in 48 states and DC, plus four companion CSVs and documentation. Inspect the full coverage and fields.
Code example
The example uses Python’s standard library and runs in a notebook, IPython or as a script. It selects each destination’s outside residence counties, ranks them by primary-job count and calculates each flow’s share of all jobs based in that destination county, including jobs held by local residents.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
from pathlib import Path
import csv
from decimal import Decimal, ROUND_HALF_UP
DATA = Path('.') # Folder containing the two downloaded sample CSVs, or the full product.
counties = [
{'work_county': '37183'}, # Wake County, NC
{'work_county': '37063'}, # Durham County, NC
]
summaries = {}
with (DATA / 'county_summary.csv').open(newline='', encoding='utf-8') as f:
for row in csv.DictReader(f):
key = row['county_code']
if key in summaries:
raise ValueError('Duplicate reference key in county_summary.csv')
summaries[key] = row
selected = {row['work_county'] for row in counties}
flows = {key: [] for key in selected}
seen = set()
with (DATA / 'county_flows.csv').open(newline='', encoding='utf-8') as f:
for row in csv.DictReader(f):
if row['work_county'] not in selected:
continue
key = (row['home_county'], row['work_county'])
if key in seen:
raise ValueError('Duplicate reference key in county_flows.csv')
seen.add(key)
if row['home_county'] != row['work_county']:
flows[row['work_county']].append(row)
results = []
for selection in counties:
code = selection['work_county']
summary = summaries.get(code)
if summary is None or summary['workplace_coverage'] != 'reported_LODES_universe':
results.append({'work_county': code, 'work_county_name': '', 'home_county': '',
'home_county_name': '', 'primary_jobs': '', 'share_of_workplace_jobs_percent': '',
'status': 'county_not_in_reference' if summary is None else 'workplace_state_unavailable'})
continue
total = int(summary['workplace_primary_jobs'])
largest = sorted(flows[code], key=lambda row: (-int(row['primary_jobs']), row['home_county']))[:3]
for row in largest:
jobs = int(row['primary_jobs'])
share = (Decimal(jobs) * 100 / total).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) if total else None
results.append({'work_county': code, 'work_county_name': summary['county_name'],
'home_county': row['home_county'], 'home_county_name': row['home_county_name'],
'primary_jobs': str(jobs), 'share_of_workplace_jobs_percent': str(share) if share is not None else '',
'status': 'reported'})
for row in results:
if row['status'] != 'reported':
print(row['work_county'], row['status'])
else:
print(f"{row['work_county_name']} <- {row['home_county_name']}: "
f"{int(row['primary_jobs']):,} primary jobs; "
f"{row['share_of_workplace_jobs_percent']}% of workplace jobs")
Replace counties with your own workplace-county selections, or load a work_county column from your CSV. Keep five-character county codes as text to preserve leading zeros. Other destinations require the full purchased files.
Analysis of the output
Wake County, NC <- Johnston County, NC: 45,143 primary jobs; 7.05% of workplace jobs
Wake County, NC <- Durham County, NC: 34,338 primary jobs; 5.36% of workplace jobs
Wake County, NC <- Mecklenburg County, NC: 19,404 primary jobs; 3.03% of workplace jobs
Durham County, NC <- Wake County, NC: 79,857 primary jobs; 32.81% of workplace jobs
Durham County, NC <- Orange County, NC: 15,523 primary jobs; 6.38% of workplace jobs
Durham County, NC <- Johnston County, NC: 7,080 primary jobs; 2.91% of workplace jobs
Wake residents hold 79,857 primary jobs based in Durham, or 32.81% of Durham’s covered workplace total. In the reverse direction, Durham residents hold 34,338 jobs in Wake, or 5.36% of Wake’s total. The direction and denominator matter: these two counties connect strongly, but each relationship has a different scale within its destination labor market.
The result identifies the largest outside sources of each county’s workforce. The percentages provide context for the counts: a large flow may still represent a modest share of the destination’s total jobs. The three displayed origins are a ranking, not the entire incoming workforce, so their percentages should not sum to 100%.
Local residence/workplace relationships are present in the sample but excluded from this ranking. The denominator includes them. For the share of incoming jobs instead, use incoming_primary_jobs from the county summary and label that different denominator explicitly.
A primary job is the highest-earning job for a worker within the covered LODES universe. The reference describes jobs held at the beginning of the second quarter of 2023. These disclosure-protected statistics do not measure actual daily trips, commuting frequency or whether a job is performed remotely. They are useful for labor-market relationships, not a direct traffic forecast.
A county absent from the reference keeps a result with county_not_in_reference; an unavailable workplace jurisdiction keeps workplace_state_unavailable. Duplicate reference keys raise an error. Alaska and Michigan lack 2023 workplace data, so residence-based totals can miss jobs in those destinations.
Add local labor-market context
Workplace employment and wages describe industry scale and pay, while resident employment and unemployment describe the local labor force. County GDP and personal income add economic output and income context. These sources have different populations, periods and geographic vintages; a matching county code is only the start of a compatible join. Choose business and labor data for your task →
Using the full dataset
Extract the purchased ZIP and replace both sample files with the complete county_flows.csv and county_summary.csv. The code runs unchanged. The main table has 788,336 residence-county/workplace-county pairs, with primary jobs and separate age, monthly-earnings and broad-industry counts. Each set of categories partitions the job total independently; they cannot be combined to infer an age-by-earnings-by-industry breakdown.
The summary separates local jobs, incoming jobs, resident jobs linked to covered workplaces and outgoing jobs linked to covered workplaces. Alaska, Michigan and Puerto Rico have geography references but unavailable workplace totals remain blank. Virgin Islands workplace coverage is explicitly unavailable and Census does not supply a block crosswalk for it. An absent county pair is not a universal proof of zero employment.
County assignments use Census’s supplied 2024 geography crosswalk for 2020 blocks, rather than assuming the first five block-code digits identify the current county. Connecticut therefore uses planning regions. Review geography before comparing with another county edition. The product does not supply a historical boundary conversion.
state_coverage.csv lists included and unavailable workplace jurisdictions; source_file_status.csv accounts for every retained OD file; measures.csv defines the counts. Dictionaries, checksums, source and processing identifiers, and independent reconciliation accompany the five CSVs.
Sources and versions
Source: U.S. Census Bureau, LEHD Origin-Destination Employment Statistics, LODES 8.4, released December 18, 2025. This edition selects 2023 primary jobs (JT01), retaining each available workplace state’s main and auxiliary OD files and the supplied block-to-county crosswalks. The technical documentation defines the records and measures.
The source was retained October 31, 2026. Observation year, publisher release and ACD processing have separate identities. This product is one fixed source edition, not a historical series or membership in future publications.
Your one-time purchase includes ACD processing improvements and documented publisher error corrections to this edition. New years or genuinely new source editions may be sold separately. Census supplies the original data free; ACD sells aggregation, documentation, validation and delivery. Read the preparation record.
Example checked October 31, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.