当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python pyspark Series.where用法及代码示例


本文简要介绍 pyspark.pandas.Series.where 的用法。

用法:

Series.where(cond: pyspark.pandas.series.Series, other: Any = nan) → pyspark.pandas.series.Series

替换条件为 False 的值。

参数

cond布尔系列

如果 cond 为 True,则保留原始值。如果为 False,则替换为其他对应的值。

other标量,系列

cond 为 False 的条目将替换为来自 other 的相应值。

返回

Series

例子

>>> from pyspark.pandas.config import set_option, reset_option
>>> set_option("compute.ops_on_diff_frames", True)
>>> s1 = ps.Series([0, 1, 2, 3, 4])
>>> s2 = ps.Series([100, 200, 300, 400, 500])
>>> s1.where(s1 > 0).sort_index()
0    NaN
1    1.0
2    2.0
3    3.0
4    4.0
dtype: float64
>>> s1.where(s1 > 1, 10).sort_index()
0    10
1    10
2     2
3     3
4     4
dtype: int64
>>> s1.where(s1 > 1, s1 + 100).sort_index()
0    100
1    101
2      2
3      3
4      4
dtype: int64
>>> s1.where(s1 > 1, s2).sort_index()
0    100
1    200
2      2
3      3
4      4
dtype: int64
>>> reset_option("compute.ops_on_diff_frames")

相关用法


注:本文由纯净天空筛选整理自spark.apache.org大神的英文原创作品 pyspark.pandas.Series.where。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。