Check if array contains a given value
Description
Check if array contains a given value
Usage
<Expr>$arr$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(
values = list(0:2, 4:6, c(NA_integer_, NA_integer_, NA_integer_)),
item = c(0L, 4L, 2L),
schema = list(values = pl$Array(pl$Float64, 3))
)
df$with_columns(
with_expr = pl$col("values")$arr$contains(pl$col("item")),
with_lit = pl$col("values")$arr$contains(1)
)
#> shape: (3, 4)
#> ┌────────────────────┬──────┬───────────┬──────────┐
#> │ values ┆ item ┆ with_expr ┆ with_lit │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ array[f64, 3] ┆ i32 ┆ bool ┆ bool │
#> ╞════════════════════╪══════╪═══════════╪══════════╡
#> │ [0.0, 1.0, 2.0] ┆ 0 ┆ true ┆ true │
#> │ [4.0, 5.0, 6.0] ┆ 4 ┆ true ┆ false │
#> │ [null, null, null] ┆ 2 ┆ false ┆ false │
#> └────────────────────┴──────┴───────────┴──────────┘