maxframe.liteframe.LiteFrame.case_when#
- LiteFrame.case_when(caselist)#
Replace values where conditions are True, evaluated in order.
Mirrors
pandas.Series.case_when: each(cond, replacement)pair is evaluated sequentially; the first condition that is True determines the replacement value for that row. Rows where no condition is True keep their original value.Both cond and replacement may be callables; when callable they are invoked with lf and should return a LiteFrame (for cond) or a LiteFrame / scalar (for replacement), matching the pandas contract where callables are computed on the Series itself.
- Parameters:
caselist (list of (condition, replacement)) – Ordered list of
(condition, replacement)pairs. condition is a boolean LiteFrame, or a callable returning one. replacement is a scalar, a LiteFrame, or a callable returning either.- Returns:
A LiteFrame with the same columns as lf.
- Return type:
See also
Examples
>>> import maxframe.liteframe as mlf >>> lf = mlf.LiteFrame({'a': [1, 2, 3, 4]}) >>> result = lf.case_when([(lf < 2, 0), (lf > 3, 10)]) >>> result.execute() a 0 0 1 2 2 3 3 10