Check if list contains a given value
Description
Check if list contains a given value
Usage
<Expr>$list$contains(item)
Arguments
item
|
Expr or something coercible to an Expr. Strings are not parsed as columns. |
Value
Expr
Examples
library("polars")
df = pl$DataFrame(
a = list(3:1, NULL, 1:2),
item = 0:2
)
df$with_columns(
with_expr = pl$col("a")$list$contains(pl$col("item")),
with_lit = pl$col("a")$list$contains(1)
)
#> shape: (3, 4)
#> ┌───────────┬──────┬───────────┬──────────┐
#> │ a ┆ item ┆ with_expr ┆ with_lit │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ list[i32] ┆ i32 ┆ bool ┆ bool │
#> ╞═══════════╪══════╪═══════════╪══════════╡
#> │ [3, 2, 1] ┆ 0 ┆ false ┆ true │
#> │ [] ┆ 1 ┆ false ┆ false │
#> │ [1, 2] ┆ 2 ┆ true ┆ true │
#> └───────────┴──────┴───────────┴──────────┘