snowflake.snowpark.functions.in_

snowflake.snowpark.functions.in_(cols: List[Union[Column, str]], *vals: Union[DataFrame, None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, list, tuple, dict, Iterable[Union[None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, list, tuple, dict]]]) Column[source]

Returns a conditional expression that you can pass to the filter or where methods to perform the equivalent of a WHERE … IN query that matches rows containing a sequence of values.

The expression evaluates to true if the values in a row matches the values in one of the specified sequences.

The following code returns a DataFrame that contains the rows in which the columns c1 and c2 contain the values: - 1 and “a”, or - 2 and “b” This is equivalent to SELECT * FROM table WHERE (c1, c2) IN ((1, 'a'), (2, 'b')).

Example:

>>> df = session.create_dataframe([[1, "a"], [2, "b"], [3, "c"]], schema=["col1", "col2"])
>>> df.filter(in_([col("col1"), col("col2")], [[1, "a"], [2, "b"]])).show()
-------------------
|"COL1"  |"COL2"  |
-------------------
|1       |a       |
|2       |b       |
-------------------
Copy

The following code returns a DataFrame that contains the rows where the values of the columns c1 and c2 in df2 match the values of the columns a and b in df1. This is equivalent to SELECT * FROM table2 WHERE (c1, c2) IN (SELECT a, b FROM table1).

Example:

>>> df1 = session.sql("select 1, 'a'")
>>> df.filter(in_([col("col1"), col("col2")], df1)).show()
-------------------
|"COL1"  |"COL2"  |
-------------------
|1       |a       |
-------------------
Copy
Args::

cols: A list of the columns to compare for the IN operation. vals: A list containing the values to compare for the IN operation.