Skip to main content

Health Data Downloader Package

The Health Data Downloader is a Python package that makes it easy to download and read real world health data.

Current data sources supported:

  • NHANES National Health and Nutrition Examination Survey (CDC)

The NHANES Submodule

If you want to download health data from NHANES this module can help you not only download the data but also add documentation from the official NHANES website, and read this data into a pandas dataframe.

NHANES is the National Health and Nutrition Examination Survey which collects data about the health of adults and children in the United States.

Note: This is not an official repository from the NHANES project nor the CDC

This project provides workflows that enable you to:

  • discover and download datasets from NHANES by component (meaning what type of data like Laboratory data, examination etc.) and by cycle (which years)
  • read the XPT files into a pandas DataFrames
  • extract NHANES variable documentation into CSV files and rename variable codes into human-readable names (such as heart_rate instead of LF321)
  • search and summarize local files if they are already downloaded

Quick start

In thie quick start we will:

  1. Install required packages.
  2. Run a download.
  3. Read and inspect data.
pip install healthdata

You can choose which components you want to download (such as Demographics, Laboratory etc.) and which years (can be either "2017-2020" or "2016"). This will also download documentation about these fields from the NHANES website to add them when the data is read. If the data is already downloaded in the output directory the module will log this and skip the download.

from healthdata.nhanes.downloader import download_nhanes_data

download_nhanes_data(
    components=["Demographics", "Examination"],
    output_dir="nhanes_data",
    years=["2017-2018"],
)

You can read the data you already downloaded (you will be prompted to download it if it doesn't exist)

from healthdata.nhanes.reader import read_nhanes_data, search_nhanes_local_data

df = read_nhanes_data("nhanes_data/2017-2018/2017/Demographics/DEMO_J.XPT")
print(df.head())

inventory = search_nhanes_local_data(search_dir="nhanes_data")
print(inventory.head())

That's all folks! Now you will see that your dataframe already includes documentation.

Current caveats

  • HTML codebook parsing depends on current NHANES page text patterns. CDC page structure changes may require parser updates.
  • Network errors and partial downloads are not retried automatically.

Upcoming Additions

Planned additions include NCBI GEO and other open health and biomedical datasets. The current release supports NHANES only.

License

This project is licensed under the MIT License. Commercial use is permitted under its terms. Downloaded datasets may be subject to separate terms set by their respective providers.

For paid support or consulting, contact the author at contact@ismail.bio.

Author

Ismail Elouafiq

Contact: contact@ismail.bio

Metadata

Release files for healthdata 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for healthdata 0.1.1
File Size Uploaded
healthdata-0.1.1.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for healthdata 0.1.1
File Interpreter ABI Platform
healthdata-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / healthdata-0.1.1.tar.gz

Download URL healthdata-0.1.1.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f9a047269311432bdfc8999f48c34a1435180635f3b0e87f8fa2b7cb6f2c73ac
BLAKE2b-256 checksum
How to use checksums
ea54286723168fb2d45ec9bb45f595efacb5ae6996750a5ed1db630dd3fb7fcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release files / healthdata-0.1.1-py3-none-any.whl

Download URL healthdata-0.1.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3b236dacf45ad775f5a71e1bb5ec49a878a29e0e03b0582e50f2c167ac87b45
BLAKE2b-256 checksum
How to use checksums
4fa318dd8d5f64176dc7ed6651f3e40b5cf271da0319abcc132603860063656f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page