ehrdata.move_to_x

Contents

ehrdata.move_to_x#

ehrdata.move_to_x(edata, features, *, layer=None, copy_columns=False)#

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

This function moves the features specified from .obs to .X or the indicated layer.

The column names in .obs are preserved in .var_names of the new object.

The new object only consists of the specified layer and .obs from the original object. That means other layers and fields such as .obsm, .varm etc. are not in the new object, providing a clean and minimal object for further analysis.

Important: The layer must be 2D.

Parameters:
edata EHRData

Central data object.

features list[str] | str

The columns to move to .X/.layers.

layer str | None (default: None)

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

copy_columns bool (default: False)

The values are copied to .X/.layers (and therefore kept in .obs) instead of being moved completely.

Return type:

EHRData

Returns:

A new data object with moved columns from .obs to .X/.layers, with

  • .X/.layers containing the original plus moved columns

  • .obs

Examples

>>> import ehrdata as ed
>>> edata = ed.dt.mimic_2(columns_obs_only=["age"])
>>> ed.move_to_x(edata, ["age"])
EHRData object with n_obs × n_vars × n_t = 1776 × 46 × 1
    shape of .X: (1776, 46)

where

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