ehrdata.move_to_obs

Contents

ehrdata.move_to_obs#

ehrdata.move_to_obs(edata, var_names, *, layer=None, copy_columns=False, copy=False)#

Move variables from .X/.layers to .obs.

This function moves the var_names specified from the indicated layer to .obs.

Important to note:

  • The layer must be 2D.

  • If copy_columns is set to False, var_names will be removed across .X/.layers.

Parameters:
edata EHRData

Central data object.

var_names list[str] | str

The columns to move to .obs.

layer str | None (default: None)

The 2D layer to use from the EHRData object. If None, the X layer is used. Must be 2D.

copy_columns bool (default: False)

If False, the columns are moved to obs and deleted from .X/.layers. If True, the values are copied to obs (and therefore kept in .X/.layers).

copy bool (default: False)

If True, a new EHRData object is returned. If False, the original object is modified inplace and None is returned.

Return type:

EHRData | None

Returns:

A new EHRData object with moved or copied columns from .X/.layers to obs.

Examples

>>> import ehrdata as ed
>>> edata = ed.dt.mimic_2()
>>> ed.move_to_obs(edata, ["age"], copy=True)
EHRData object with n_obs × n_vars × n_t = 1776 × 45 × 1
    obs: 'age'
    shape of .X: (1776, 45)

where

>>> edata
EHRData object with n_obs × n_vars × n_t = 1776 × 46 × 1
    shape of .X: (1776, 46)