Compare quarterly Medicare drug payment limits in Python

Compare two HCPCS drug codes across quarters, retain billing units and attach a same-quarter benchmark to an NDC–HCPCS relationship.

Compare payment benchmarks for a drug portfolio

An analyst follows Medicare payment benchmarks for aflibercept and pembrolizumab and wants to compare the third and fourth quarters of 2026. The product supplies the effective quarter, HCPCS code, stated billing unit, published payment limit and CMS notes in one table.

The optional input.csv selects two real HCPCS codes, J0178 and J9271. Those same choices appear in the portfolio list in the Python code below. The selections define the research task; the payment values are unchanged CMS observations.

Download both files into your working folder. payment_limits.csv is a genuine subset of the paid main table: all four quarters for these two codes, retaining all 20 fields. ndra_restrictions.csv supplies the complete 22-row restriction context table. It is separate from the rate table and is not a comprehensive list of payment restrictions. The full $29 purchase contains 3,443 rate records across 908 codes and six CSV tables.

Code example

Run this code in a notebook cell, IPython or a Python script. It uses the standard library. The comparison checks that both rates are reported and that dosage and description agree, and avoids codes listed in the selected quarters' restriction files.

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

# Real HCPCS research selections, also supplied in example_input.csv.
portfolio = [{"hcpcs_code": "J0178"}, {"hcpcs_code": "J9271"}]
previous_quarter, current_quarter = "2026-Q3", "2026-Q4"

with open("payment_limits.csv", newline="", encoding="utf-8") as f:
    rates = {(r["quarter"], r["hcpcs_code"]): r for r in csv.DictReader(f)}
with open("ndra_restrictions.csv", newline="", encoding="utf-8") as f:
    restrictions = {(r["quarter"], r["hcpcs_code"]) for r in csv.DictReader(f)}

results = []
for selection in portfolio:
    code = selection["hcpcs_code"]
    before = rates.get((previous_quarter, code))
    after = rates.get((current_quarter, code))
    if before is None or after is None:
        print(f"{code}: not present in both quarterly rate files")
        continue
    if any((q, code) in restrictions for q in (previous_quarter, current_quarter)):
        print(f"{code}: listed in a selected quarter's NDRA restriction file; review source context")
        continue
    if before["billing_unit"] != after["billing_unit"] or before["short_description"] != after["short_description"]:
        print(f"{code}: changed dosage or description; inspect before comparing")
        continue
    if any(r["payment_limit_status"] != "reported" for r in (before, after)):
        print(f"{code}: a payment limit is unavailable")
        continue
    old, new = Decimal(before["payment_limit_usd"]), Decimal(after["payment_limit_usd"])
    if old == 0:
        print(f"{code}: zero baseline; percentage change is undefined")
        continue
    change = (new / old - 1) * 100
    results.append({"hcpcs_code": code, "description": after["short_description"],
                    "billing_unit": after["billing_unit"], "previous_limit_usd": str(old),
                    "current_limit_usd": str(new), "change_percent": f"{change:.2f}"})
    print(f"{code} | {after['short_description']} | per {after['billing_unit']} | "
          f"{previous_quarter} ${old:.3f} → {current_quarter} ${new:.3f} | {change:+.2f}%")
    for quarter, row in ((previous_quarter, before), (current_quarter, after)):
        if row["notes"]:
            print(f"  {quarter} CMS note: {row['notes']}")

Replace portfolio with your own HCPCS codes, or load that column from your CSV using csv.DictReader. Select the two quarters with previous_quarter and current_quarter. Keep CMS notes with the result when interpreting a rate.

Analysis of the output

J0178 | Aflibercept injection | per 1 MG | 2026-Q3 $743.605 → 2026-Q4 $722.251 | -2.87%
J9271 | Inj pembrolizumab | per 1 MG | 2026-Q3 $60.645 → 2026-Q4 $62.253 | +2.65%

For J0178, the published limit declines from $743.605 to $722.251 per 1 MG, a 2.87% decrease. For J9271, it increases from $60.645 to $62.253 per 1 MG, a 2.65% increase. These are changes in CMS's published payment benchmarks. They do not measure spending, drug utilization, a patient's bill or an observed claim payment.

The full comparison table follows the same principle: changes in dosage or short description require review before comparing rates. Added and removed codes describe differences between retained source tables, not drug approvals or discontinuations. An unavailable rate remains blank with an explicit status; it is not replaced with zero.

Connect a package NDC to its quarterly benchmark

The companion NDC–HCPCS crosswalk supplies the missing package-to-code relationship. Download its free crosswalk.csv sample into the same folder. It contains two Keytruda package sizes and an Aranesp package; the packages list below selects the two Keytruda NDCs. Run this second example independently after downloading the rate sample above.

Python 3.10+ · optional companion join
import csv

# Two genuine Q4 package identifiers from the companion NDC–HCPCS sample.
packages = [{"quarter": "2026-Q4", "ndc11": "00006302602"},
            {"quarter": "2026-Q4", "ndc11": "00006302604"}]
with open("crosswalk.csv", newline="", encoding="utf-8") as f:
    crosswalk = list(csv.DictReader(f))
with open("payment_limits.csv", newline="", encoding="utf-8") as f:
    rates = {(r["quarter"], r["hcpcs_code"]): r for r in csv.DictReader(f)}

results = []
for package in packages:
    matches = [r for r in crosswalk if r["quarter"] == package["quarter"]
               and r["ndc11"] == package["ndc11"]]
    if not matches:
        print(f"{package['ndc11']}: no crosswalk relationship in this quarter")
    for match in matches:
        rate = rates.get((package["quarter"], match["hcpcs_code"]))
        same_unit = rate is not None and match["hcpcs_dosage"] == rate["billing_unit"]
        usable = same_unit and rate["payment_limit_status"] == "reported"
        result = {"quarter": package["quarter"], "ndc11": package["ndc11"],
                  "hcpcs_code": match["hcpcs_code"], "crosswalk_dosage": match["hcpcs_dosage"],
                  "payment_unit": rate["billing_unit"] if rate else "",
                  "payment_limit_usd": rate["payment_limit_usd"] if usable else "",
                  "status": "benchmark_attached" if usable else "review_missing_rate_or_unit"}
        results.append(result)
        print(f"{result['ndc11']} | {result['hcpcs_code']} | crosswalk {result['crosswalk_dosage']} | "
              f"payment unit {result['payment_unit']} | ${result['payment_limit_usd']} | {result['status']}")
00006302602 | J9271 | crosswalk 1 MG | payment unit 1 MG | $62.253 | benchmark_attached
00006302604 | J9271 | crosswalk 1 MG | payment unit 1 MG | $62.253 | benchmark_attached

Both packages attach to J9271 and the same $62.253 benchmark per 1 MG in Q4. The crosswalk dosage and payment-unit text agree. The code keeps every matching relationship and does not multiply the benchmark by package quantities. This establishes a research join, not a package reimbursement calculation or confirmation of claim eligibility.

Using the full dataset

Extract the purchased ZIP and replace the two sample files with the full payment_limits.csv and ndra_restrictions.csv. The first example runs unchanged. The optional package join also needs the companion crosswalk purchase for NDCs outside its free sample.

The six CSVs are the rate table, quarterly_changes.csv, ndra_restrictions.csv, coverage.csv, source_row_status.csv and source_files.csv. The 2,625 comparison rows include earlier and later values and comparison statuses. The main key is quarter plus hcpcs_code. An ASP reference quarter is a different field from the payment's effective quarter.

The 2020–2024 Part B spending history answers a different question about observed aggregate spending and utilization. A 2026 payment benchmark cannot stand in for those historical measures.

Sources and versions

Source: CMS quarterly Part B drug payment files for January, April, July and October 2026. The landing page dates the Q1–Q3 revisions September 15 and the Q4 publication September 17. ACD retained the available files on October 25, 2026. These are revised files, not original-as-published historical vintages.

The prepared rate table includes A/J/P/Q Level II codes. Numeric Level I/CPT codes and descriptions are excluded. CSV/workbook differences are reconciled: 108 rows have numeric rounding differences at the CSV's declared precision, and 19 CSV-only trailing blanks remain accounted for. A9606 has an unavailable rate in all four quarters and retains its source note. The restriction files are noncomprehensive; January's archive supplies none, which does not establish that no restrictions applied.

This is the first ACD edition of the retained quarters, with no automatic refresh. The change sheet describes the quarter comparisons and preparation separately. Same-source processing improvements are included; genuinely new source editions may be sold separately. Original CMS files are free. ACD sells preparation, comparison, documentation, validation and delivery. Independent preparation; no CMS endorsement.

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