Find reported drugs for an NPI roster in Python

Find the leading reported drugs for real NPIs, then compare visible drug activity with separately published provider totals.

Find the drugs reported under an NPI

You have an NPI roster and want to see which drugs account for its reported Medicare Part D activity. This example selects three North Carolina Family Practice prescribers, lists their three highest-claim drug groups and compares the public drug rows with each provider’s separately published total.

The optional input.csv contains the three genuine NPI selections. The same selections appear in the roster list in the Python code below. No providers, patients or prescribing observations are invented.

Download the three sample tables into your working folder. provider_drugs.csv contains all 162 published drug relationships for these NPIs; prescribers.csv contains their identity and coverage records; drugs.csv contains the 108 matching drug-name groups. Every field and value comes from the paid files. Drug-level summary columns still describe the full published source, not just these three prescribers.

The complete $49 reference contains 28,023,892 provider–drug records, 3,159 exact drug-name pairs and provider coverage comparisons. It includes 2024 observations from two dated CMS releases. Review the full product and source dates.

Code example

This standard-library code works in a notebook cell, IPython or a script. It reads the large relationship table one row at a time and keeps only your selected NPIs. Extract the files first; you do not need to load the entire table into a dataframe.

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
from pathlib import Path

# Three genuine NPI selections, also supplied in the optional input.csv.
roster = [{'npi': '1053767749'}, {'npi': '1053768739'}, {'npi': '1053798660'}]
selected = {item['npi'] for item in roster}
with Path('drugs.csv').open(encoding='utf-8', newline='') as f:
    drugs = {r['drug_id']: r for r in csv.DictReader(f)}
with Path('prescribers.csv').open(encoding='utf-8', newline='') as f:
    providers = {r['npi']: r for r in csv.DictReader(f) if r['npi'] in selected}
activity = {npi: [] for npi in selected}
# Stream the large table: retain only the selected NPIs, not the full file.
with Path('provider_drugs.csv').open(encoding='utf-8', newline='') as f:
    for row in csv.DictReader(f):
        if row['npi'] in selected:
            activity[row['npi']].append(row)

results = []
for item in roster:
    npi = item['npi']
    provider = providers.get(npi)
    if provider is None:
        print(f'{npi}: absent from this edition; no zero activity inferred.')
        continue
    print(f"{provider['first_name']} {provider['last_or_organization_name']} | NPI {npi} | {provider['specialty']}")
    percentage = provider['reported_claim_share_percent']
    coverage = f'{Decimal(percentage):.1f}%' if percentage else 'unavailable'
    print(f"  Public drug rows: {provider['drug_pair_count']}; share of separately reported provider claims: {coverage}")
    ranked = sorted(activity[npi], key=lambda r: (-Decimal(r['total_claims']), r['drug_id']))
    for row in ranked[:3]:
        drug = drugs[row['drug_id']]
        beneficiaries = row['total_beneficiaries'] or 'suppressed'
        result = {'npi': npi, 'brand_name': drug['brand_name'], 'generic_name': drug['generic_name'],
                  'claims': row['total_claims'], 'beneficiaries': beneficiaries,
                  'gross_drug_cost': row['total_drug_cost'], 'provider_reported_claim_share': coverage}
        results.append(result)
        print(f"  {drug['brand_name']} ({drug['generic_name']}): {int(Decimal(row['total_claims'])):,} claims; {beneficiaries} beneficiaries; ${Decimal(row['total_drug_cost']):,.2f} gross cost")

Replace roster with your own NPI strings, or read its npi column from a CSV. The code sorts each provider’s reported rows by claims and prints the top three; it does not discard the other relationships from the sample or purchased files.

Analysis of the output

Sean Vidulich | NPI 1053767749 | Family Practice
  Public drug rows: 95; share of separately reported provider claims: 91.5%
  Atorvastatin Calcium (Atorvastatin Calcium): 434 claims; 132 beneficiaries; $4,996.34 gross cost
  Levothyroxine Sodium (Levothyroxine Sodium): 224 claims; 64 beneficiaries; $3,939.35 gross cost
  Lisinopril (Lisinopril): 207 claims; 66 beneficiaries; $2,334.80 gross cost
Eugene Wang | NPI 1053768739 | Family Practice
  Public drug rows: 33; share of separately reported provider claims: 70.9%
  Atorvastatin Calcium (Atorvastatin Calcium): 173 claims; 67 beneficiaries; $1,211.56 gross cost
  Amlodipine Besylate (Amlodipine Besylate): 131 claims; 50 beneficiaries; $500.67 gross cost
  Lisinopril (Lisinopril): 100 claims; 35 beneficiaries; $437.06 gross cost
Laura Gay | NPI 1053798660 | Family Practice
  Public drug rows: 34; share of separately reported provider claims: 65.8%
  Atorvastatin Calcium (Atorvastatin Calcium): 105 claims; 30 beneficiaries; $1,447.36 gross cost
  Levothyroxine Sodium (Levothyroxine Sodium): 69 claims; 16 beneficiaries; $538.49 gross cost
  Hydrochlorothiazide (Hydrochlorothiazide): 53 claims; 15 beneficiaries; $256.19 gross cost

Atorvastatin Calcium is the highest-claim reported group for each of these three selections: 434, 173 and 105 claims respectively. Claims include refills. The associated beneficiary counts describe people receiving that drug under that NPI; adding them across drugs would double count some people.

The public detail covers 91.5%, 70.9% and 65.8% of the separately reported provider claims. That difference matters when comparing a drug’s share across providers: a share of the visible drug rows and a share of all provider claims use different denominators. CMS omits provider–drug combinations with ten or fewer claims. The detail and provider-summary files also have different publisher revision dates, so the uncovered share is not a pure estimate of suppression.

Costs are gross amounts before rebates and include multiple payers. They are neither Medicare’s net cost nor a pharmacy unit price. Differences in drugs, patient mix, attribution and publication coverage mean these figures do not rank clinical quality or prescribing efficiency.

A blank beneficiary count prints as suppressed. An NPI without public drug rows can still have a provider-summary record and substantial activity. An NPI absent from both tables produces an explicit message; neither case proves zero prescribing. Original age-65 suppression flags remain available in the CSV, without reconstructing hidden cells.

Using the full dataset

Extract the purchased ZIP and replace all three sample CSVs with their complete counterparts. The code runs unchanged, although scanning 28 million records takes longer. The main CSV exceeds a spreadsheet’s row limit; use streaming Python or import it into a database.

year + npi + drug_id uniquely identifies a relationship. Brand and generic names are present directly in the main table; drug_id joins the exact name pair to its separate published-activity summary. It does not identify an NDC, strength, dosage form, RxCUI or ATC classification. A similar name is not proof of an equivalent formulation.

prescribers.csv includes the union of the detail and provider-summary NPIs, original identity provenance, coverage status and any disagreement between the two source identities. State abbreviations and FIPS are preserved as reported. Provider demographics are historical and do not form a current contact directory.

For broader NPI activity and specialty comparisons, use the separate Prescriber & Specialty Reference. For drug trends across states and years, use Part D State Drug Utilization History. Each covers a different reporting level. Explore prescribers and prescribing.

Sources and versions

Source: CMS Medicare Part D Prescribers by Provider and Drug, 2024 observations, modified May 21, 2026. The companion provider summary also covers 2024 but was modified August 3, 2026. ACD retained both October 26, 2026 UTC.

The CMS methodology explains exclusions, suppression, attribution and provider demographics. The source and preparation record separates these publisher dates from ACD’s processing revision. Processing improvements for the retained inputs are included; new source editions may be sold separately.

The government sources are available free. ACD sells documented preparation, validated relationships, reproducibility and delivery. No automatic source refresh is promised.

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