data.load_dataset()

Load a bundled dataset by name.

Usage

Source

data.load_dataset(
    name,
    *,
    backend=None,
)

Greenwood ships several classic survival-analysis datasets from R’s survival package, stored as gzipped CSVs. This function decompresses them on the fly and returns a DataFrame in your preferred backend.

Parameters

name: str

One of available_datasets() (e.g., "lung", "veteran", "ovarian", "pbc", "pbcseq", "colon", "mgus2").

backend: str | None = None
"pandas" or "polars". When left as None (the default), Greenwood picks a backend for you: it prefers Polars if it is installed, otherwise uses Pandas, and raises if neither is available.

Returns

DataFrame
A Polars or Pandas DataFrame with the dataset contents.

Examples

Load the NCCTG lung cancer dataset as a Polars DataFrame:

import greenwood as gw

# Load the NCCTG lung cancer dataset as a Polars DataFrame
lung = gw.load_dataset("lung", backend="polars")
lung.head()
shape: (5, 10)
insttimestatusagesexph.ecogph.karnopat.karnomeal.calwt.loss
i64i64i64i64i64i64i64i64i64i64
330627411901001175null
3455268109090122515
31010156109090null15
5210257119060115011
18832601010090null0

See all available dataset names:

# List all available dataset names
gw.available_datasets()
['colon', 'lung', 'mgus2', 'ovarian', 'pbc', 'pbcseq', 'veteran']