ehrdata.move_to_x#
- ehrdata.move_to_x(edata, features, *, layer=None, copy_columns=False)#
Move variables from
.obsto.X/.layers.This function moves the
featuresspecified from.obsto.Xor the indicatedlayer.The column names in
.obsare preserved in.var_namesof the new object.The new object only consists of the specified
layerand.obsfrom the original object. That means other layers and fields such as.obsm,.varmetc. are not in the new object, providing a clean and minimal object for further analysis.Important: The
layermust 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
EHRDataobject. IfNone,.Xis used.- copy_columns
bool(default:False) The values are copied to
.X/.layers(and therefore kept in.obs) instead of being moved completely.
- edata
- Return type:
- Returns:
A new data object with moved columns from
.obsto.X/.layers, with.X/.layerscontaining 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)