Tools for processing and analyzing National Cancer Database (NCDB) data
Project description
ncdb-tools
A Python package for efficiently processing and analyzing National Cancer Database (NCDB) data files.
Installation
pip install ncdb-tools
Important Notice
This package provides tools for processing NCDB data files. You must obtain NCDB data through official channels - this package does not include any patient data. The National Cancer Database (NCDB) is a clinical oncology database sourced from hospital registry data that are collected in more than 1,500 Commission on Cancer (CoC)-accredited facilities.
Quick Start
import ncdb_tools
# Convert all NCDB data files in a directory to parquet format
paths = ncdb_tools.build_database("/path/to/NCDB_DATA/")
# The function will:
# 1. Find all .dat files
# 2. Find the SAS labels file
# 3. Create a new subdirectory with today's date
# 4. Convert all files to parquet format
# 5. Generate a comprehensive data dictionary
# 6. Create a summary report
print(f"Database created in: {paths['output_dir']}")
Working with the Data
After building the database, you can query the parquet files using NCDB-specific filters and standard Polars operations:
import polars as pl
# Load data with NCDB-specific filters
query = ncdb_tools.load_data("path/to/parquet_directory/")
# Chain NCDB filters, then use Polars for analysis
df = (
query
.filter_by_year(2021)
.filter_by_primary_site("C509") # Breast
.filter_by_histology([8140, 8500]) # Adenocarcinoma codes
.drop_missing_vital_status()
.lazy_frame() # Get Polars LazyFrame
)
# Use standard Polars operations
results = (
df
.filter(pl.col("AGE") >= 50)
.group_by(["SEX", "RACE"])
.agg([
pl.count().alias("count"),
pl.col("AGE").mean().alias("mean_age")
])
.collect()
)
The query interface provides these NCDB-specific filters:
filter_by_year()- Filter by year of diagnosisfilter_by_primary_site()- Filter by ICD-O-3 primary site codesfilter_by_histology()- Filter by histology codes (accepts integers or strings)drop_missing_vital_status()- Remove cases with missing vital status
After applying NCDB filters, use .lazy_frame() to access the Polars LazyFrame for further analysis.
Features
- Efficiently converts NCDB fixed-width text files to parquet format
- Automatically parses SAS labels for meaningful column names
- Generates comprehensive data dictionaries in CSV, JSON, and HTML formats
- Memory-efficient processing using Polars
- Simple, high-level API for common tasks
- NCDB-specific data filters and transformations
- Compatible with all Python 3.9+ versions
Requirements
- Python 3.9 or higher
- NCDB data files (obtained through official channels)
License
MIT License - see LICENSE file for details.
Disclaimer
This software is provided for research purposes. Users are responsible for ensuring compliance with all applicable data use agreements and privacy regulations when working with NCDB data.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ncdb_tools-0.1.0.tar.gz.
File metadata
- Download URL: ncdb_tools-0.1.0.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f89e561a60c196b666ed751c432f866950126bc024ae34ad0f35691343ec7d88
|
|
| MD5 |
4d12aa0039adc416f74ea7e9a0ae988c
|
|
| BLAKE2b-256 |
90b8a2b328dae9c2542ceb7b9b716bf50a6c83856bb38c91314c94dd31dc11d1
|
File details
Details for the file ncdb_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ncdb_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28e17f8f5ace29df1ea24b799bf50c2bfd3dfd6b6fef0d3becf9ad99cb446496
|
|
| MD5 |
70625d6ff1ecb6513ad446cbbb7ae20a
|
|
| BLAKE2b-256 |
24fc1c7d3502cf724c2b20ddcf197b60cda1d3d025fcd10e018852b56f254b59
|