maxframe.dataframe.Series.case_when#
- Series.case_when(caselist)#
替换条件为 True 的值。
- 参数:
caselist (A list of tuples of conditions and expected replacements) -- 形式为:
(condition0, replacement0),(condition1, replacement1),...。condition应该是一个一维布尔数组类对象或可调用对象。如果condition是可调用对象,则会在 Series 上计算,并应返回一个布尔 Series 或数组。该可调用对象不得更改输入 Series (尽管 pandas 不会检查)。replacement应该是一个一维数组类对象、标量或可调用对象。如果replacement是可调用对象,则会在 Series 上计算,并应返回一个标量或 Series。该可调用对象不得更改输入 Series。- 返回类型:
参见
Series.mask替换条件为 True 的值。
示例
>>> import maxframe.dataframe as md >>> c = md.Series([6, 7, 8, 9], name='c') >>> a = md.Series([0, 0, 1, 2]) >>> b = md.Series([0, 3, 4, 5])
>>> c.case_when(caselist=[(a.gt(0), a), # condition, replacement ... (b.gt(0), b)]).execute() 0 6 1 3 2 1 3 2 Name: c, dtype: int64