How can I achieve the equivalents of SQL's IN and NOT IN?
I have a list with the required values. Here's the scenario:
import pandas as pd
import polars as pl
exclude_fruit = ["apple", "orange"]
df = pl.DataFrame(
{
"A": [1, 2, 3, 4, 5, 6],
"fruits": ["banana", "banana", "apple", "apple", "banana", "orange"],
"B": [5, 4, 3, 2, 1, 6],
"cars": ["beetle", "audi", "beetle", "beetle", "beetle", "frog"],
"optional": [28, 300, None, 2, -30, 949],
}
)
df.filter(~pl.select("fruits").str.contains(exclude_fruit))
df.filter(~pl.select("fruits").to_pandas().isin(exclude_fruit))
df.filter(~pl.select("fruits").isin(exclude_fruit))