Nóta
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað aðskrá þig inn eða breyta skráasöfnum.
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað að breyta skráasöfnum.
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|
# +---+-----+