Join package NDCs to HCPCS codes in Python

Add quarter-specific HCPCS codes and package-unit context to NDC records, keeping multiple matches visible.

Add billing-code context to a drug package list

An analyst has package NDCs and wants the CMS HCPCS code and billing-unit context for the fourth quarter of 2026. The crosswalk adds the code, its short description, the number of items in the package and the supplied billing units per package. It also preserves cases where CMS lists more than one code for an NDC.

The optional input.csv selects three real NDCs: two Keytruda package sizes and one Aranesp package. Those same quarter and NDC selections appear in the packages list in the Python code below. No package observations or billing values are invented.

Download crosswalk.csv into your working folder. This is a genuine subset of the paid crosswalk, containing all four Q4 relationships for the three selected NDCs, with all 21 columns retained. The full purchase contains 29,044 relationships across all four 2026 quarters, plus comparison, coverage and source-accounting tables.

Code example

Run this code in a notebook cell, IPython or a Python script. It uses only Python's standard library. The lookup key includes the effective quarter; each match remains a separate result.

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 collections import defaultdict

# Selected real NDCs; these requests are also in example_input.csv.
packages = [
    {"quarter": "2026-Q4", "ndc11": "00006302602"},
    {"quarter": "2026-Q4", "ndc11": "00006302604"},
    {"quarter": "2026-Q4", "ndc11": "55513000204"},
]

lookup = defaultdict(list)
with open("crosswalk.csv", newline="", encoding="utf-8-sig") as file:
    for row in csv.DictReader(file):
        if row["ndc11"]:
            lookup[(row["quarter"], row["ndc11"])].append(row)

results = []
for package in packages:
    matches = lookup[(package["quarter"], package["ndc11"])]
    for match in matches or [None]:
        result = {**package, "hcpcs_code": match["hcpcs_code"] if match else "",
                  "description": match["short_description"] if match else "",
                  "items_in_package": match["package_quantity"] if match else "",
                  "billing_units_per_ndc": match["billing_units_per_ndc"] if match else "",
                  "match_count": len(matches)}
        results.append(result)

for row in results:
    print(f"{row['quarter']} | {row['ndc11']} | {row['hcpcs_code']} | "
          f"{row['description']} | items={row['items_in_package']} | "
          f"billing units/NDC={row['billing_units_per_ndc']} | matches={row['match_count']}")

Replace packages with your own quarter and NDC11 values, or load those columns from your CSV using csv.DictReader. Keep NDCs as strings, including their leading zeros. The code leaves the added fields blank for unmatched inputs and reports a match count of zero.

Analysis of the output

2026-Q4 | 00006302602 | J9271 | Inj pembrolizumab | items=1 | billing units/NDC=100 | matches=1
2026-Q4 | 00006302604 | J9271 | Inj pembrolizumab | items=2 | billing units/NDC=200 | matches=1
2026-Q4 | 55513000204 | J0881 | Darbepoetin alfa, non-esrd | items=4 | billing units/NDC=100 | matches=2
2026-Q4 | 55513000204 | J0882 | Darbepoetin alfa, esrd use | items=4 | billing units/NDC=100 | matches=2

The two Keytruda packages map to J9271, the pembrolizumab billing code. The first has one item and 100 supplied billing units per NDC; the second has two items and 200 billing units. Those values describe the package in CMS's crosswalk. They are not dollars, patients or recommended doses.

Aranesp NDC 55513000204 has two source relationships: J0881 for non-ESRD use and J0882 for ESRD use. The code retains both descriptions and reports match_count=2. An NDC alone does not determine which billing code applies to a claim. Choosing the first match would discard this distinction.

In the full file, billing_units_per_item, package_quantity and billing_units_per_ndc remain separate. unit_arithmetic_status flags rows where the supplied multiplication differs by more than 0.000001. CMS's values are retained for review; the flag is not a confirmed error or an instruction to recalculate a claim.

A missing match means the selected NDC and quarter are absent from this ASP Level II scope. Check the identifier format, quarter and source coverage before interpreting absence. Neither a match nor a missing row establishes Medicare coverage, payment eligibility or drug availability.

Using the full dataset

Extract the purchased ZIP and replace the sample crosswalk.csv with the full file. The same code runs unchanged. Select a quarter before counting packages: the four-quarter table includes repeated NDCs across time, and some NDCs have several HCPCS relationships within a quarter.

The five CSV tables are the crosswalk, quarterly_changes.csv, coverage.csv, source_row_status.csv and source_files.csv. The change table compares adjacent quarters under the same preparation recipe. Changed rows carry the earlier and later field values; additions and removals describe these retained files, not drug launches or discontinuations.

The FDA NDC reference can add package and product context where dates and identifiers overlap. The Part B spending history uses HCPCS codes for 2020–2024. This 2026 crosswalk does not establish historical code equivalence or allocate those aggregate spending totals to individual packages.

Sources and versions

Source: CMS quarterly ASP NDC–HCPCS crosswalks for January, April, July and October 2026, captured October 24, 2026 UTC. January and April files were revised March 30; July was published June 17 and October September 17. These revised files are not a reconstruction of what was originally published at each quarter's start.

The product includes ASP A/J/Q Level II rows. Numeric Level I/CPT codes and descriptions, AWP, OPPS, PrEP, seasonal-vaccine crosswalks and payment-rate files are outside its scope. ACD reconciles each included CSV with its original workbook and accounts for exclusions. One scientific-notation identifier is restored from the exact workbook value; it remains an alternate identifier with a blank ndc11.

This is the first ACD release of the four retained quarters. Source periods and revision dates are separate from ACD's preparation date. The quarterly change sheet explains the comparisons. CMS supplies the original files free; ACD sells preparation, comparison, documentation, validation and delivery. Independent preparation; no CMS endorsement. Same-source processing improvements are included, while genuinely new source editions may be sold separately.

Example checked October 24, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.