Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Check if the column value is in a list of values.
Syntax
isin(*cols)
Parameters
| Parameter | Type | Description |
|---|---|---|
cols |
values | List of values to check against |
Returns
Column (boolean)
Examples
Example 1: Filter rows with names in the specified values.
df = spark.createDataFrame([(2, "Alice"), (5, "Bob"), (8, "Mike")], ["age", "name"])
df[df.name.isin("Bob", "Mike")].orderBy("age").show()
# +---+----+
# |age|name|
# +---+----+
# | 5| Bob|
# | 8|Mike|
# +---+----+
Example 2: Filter rows with ages in the specified list.
df[df.age.isin([1, 2, 3])].show()
# +---+-----+
# |age| name|
# +---+-----+
# | 2|Alice|
# +---+-----+
Example 3: Filter rows with names not in the specified values.
df[~df.name.isin("Alice", "Bob")].show()
# +---+----+
# |age|name|
# +---+----+
# | 8|Mike|
# +---+----+
Example 4: Use a DataFrame as an IN subquery.
df.where(df.age.isin(spark.range(6))).orderBy("age").show()
# +---+-----+
# |age| name|
# +---+-----+
# | 2|Alice|
# | 5| Bob|
# +---+-----+