bigframes.pandas.Series.case_when#
- Series.case_when(caselist) Series[source]#
Replace values where the conditions are True.
Examples:
>>> c = bpd.Series([6, 7, 8, 9], name="c") >>> a = bpd.Series([0, 0, 1, 2]) >>> b = bpd.Series([0, 3, 4, 5])
>>> c.case_when( ... caselist=[ ... (a.gt(0), a), # condition, replacement ... (b.gt(0), b), ... ] ... ) 0 6 1 3 2 1 3 2 Name: c, dtype: Int64
If you’d like to change the type, add a case with the condition True at the end of the case list
>>> c.case_when( ... caselist=[ ... (a.gt(0), 'a'), # condition, replacement ... (b.gt(0), 'b'), ... (True, 'c'), ... ] ... ) 0 c 1 b 2 a 3 a Name: c, dtype: string
See also:
bigframes.pandas.Series.mask(): Replace values where the condition is True.
- Parameters:
caselist (A list of tuples of conditions and expected replacements) – Takes the form:
(condition0, replacement0),(condition1, replacement1), … .conditionshould be a 1-D boolean array-like object or a callable. Ifconditionis a callable, it is computed on the Series and should return a boolean Series or array. The callable must not change the input Series (though pandas doesn`t check it).replacementshould be a 1-D array-like object, a scalar or a callable. Ifreplacementis a callable, it is computed on the Series and should return a scalar or Series. The callable must not change the input Series (though pandas doesn`t check it).- Returns:
bigframes.pandas.Series