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


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


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

用法:

Series.isin(values: Sequence[Any]) → IndexOpsLike

检查values是否包含在Series或Index中。

返回一个布尔系列或索引,显示系列中的每个元素是否与传递的 values 序列中的元素完全匹配。

参数

values设置或list-like

要测试的值序列。

返回

isin系列(bool dtype)或索引(bool dtype)

例子

>>> s = ps.Series(['lama', 'cow', 'lama', 'beetle', 'lama',
...                'hippo'], name='animal')
>>> s.isin(['cow', 'lama'])
0     True
1     True
2     True
3    False
4     True
5    False
Name: animal, dtype: bool

将单个字符串作为 s.isin('lama') 传递将引发错误。改为使用一个元素的列表:

>>> s.isin(['lama'])
0     True
1    False
2     True
3    False
4     True
5    False
Name: animal, dtype: bool
>>> s.rename("a").to_frame().set_index("a").index.isin(['lama'])
Index([True, False, True, False, True, False], dtype='object', name='a')

相关用法


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