ehrdata.move_to_obs#
- ehrdata.move_to_obs(edata, var_names, *, layer=None, copy_columns=False, copy=False)#
Move variables from
.X/.layersto.obs.This function moves the
var_namesspecified from the indicatedlayerto.obs.Important to note:
The
layermust be 2D.If
copy_columnsis set toFalse,var_nameswill 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
EHRDataobject. IfNone, theXlayer is used. Must be 2D.- copy_columns
bool(default:False) If False, the columns are moved to
obsand deleted from.X/.layers. IfTrue, the values are copied to obs (and therefore kept in.X/.layers).- copy
bool(default:False) If
True, a newEHRDataobject is returned. IfFalse, the original object is modified inplace andNoneis returned.
- edata
- Return type:
- Returns:
A new
EHRDataobject with moved or copied columns from.X/.layerstoobs.
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)