leaspy.io.data.data module

class Data

Bases: object

Main data container, initialized from a csv file or a pandas.DataFrame.

Methods

from_csv_file(path, **kws)

Create a Data object from a CSV file.

from_dataframe(df, **kws)

Create a Data object from a pandas.DataFrame.

from_individuals(indices, timepoints, ...)

Create a Data class object from lists of ID, timepoints and the corresponding values.

get_by_idx(idx)

Get the IndividualData of a an individual identified by its ID.

load_cofactors(df, *[, cofactors])

Load cofactors from a pandas.DataFrame to the Data object

to_dataframe(*[, cofactors])

Return the subjects' observations in a pandas.DataFrame along their ID and ages at all visits.

static from_csv_file(path: str, **kws)

Create a Data object from a CSV file.

Parameters
pathstr

Path to the CSV file to load (with extension)

**kws

Keyword arguments that are sent to CSVDataReader

Returns
Data
static from_dataframe(df: DataFrame, **kws)

Create a Data object from a pandas.DataFrame.

Parameters
dfpandas.DataFrame

Dataframe containing ID, TIME and features.

**kws

Keyword arguments that are sent to DataframeDataReader

Returns
Data
static from_individuals(indices: List[str], timepoints: List[List], values: List[List], headers: List[str])

Create a Data class object from lists of ID, timepoints and the corresponding values.

Parameters
indiceslist[str]

Contains the individuals’ ID.

timepointslist[array-like 1D]

For each individual i, list of ages at visits. Number of timepoints is referred below as n_timepoints_i

valueslist[array-like 2D]

For each individual i, all values at visits. Shape is (n_timepoints_i, n_features).

headerslist[str]

Contains the features’ names.

Returns
Data

Data class object with all ID, timepoints, values and features’ names.

get_by_idx(idx: str)

Get the IndividualData of a an individual identified by its ID.

Parameters
idxIDType

The identifier of the patient you want to get the individual data.

Returns
IndividualData
load_cofactors(df: DataFrame, *, cofactors: Optional[List[str]] = None)

Load cofactors from a pandas.DataFrame to the Data object

Parameters
dfpandas.DataFrame

The dataframe where the cofactors are stored. Its index should be ID, the identifier of subjects and it should uniquely index the dataframe (i.e. one row per individual).

cofactorslist[str] or None (default)

Names of the column(s) of df which shall be loaded as cofactors. If None, all the columns from the input dataframe will be loaded as cofactors.

Raises
LeaspyDataInputError
to_dataframe(*, cofactors=None)

Return the subjects’ observations in a pandas.DataFrame along their ID and ages at all visits.

Parameters
cofactorslist[str], ‘all’, or None (default None)

Contains the cofactors’ names to be included in the DataFrame. If None (default), no cofactors are returned. If “all”, all the available cofactors are returned.

Returns
pandas.DataFrame

Contains the subjects’ ID, age and scores (optional - and cofactors) for each timepoint.

Raises
LeaspyDataInputError