Count how often a value occurs in every sub-array
Description
Count how often a value occurs in every sub-array
Usage
<Expr>$arr$count_matches(element)
Arguments
element
|
An Expr or something coercible to an Expr that produces a single value. |
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(
values = list(c(1, 2), c(1, 1), c(2, 2))
)$cast(pl$Array(pl$Int64, 2))
df$with_columns(number_of_twos = pl$col("values")$arr$count_matches(2))
#> shape: (3, 2)
#> ┌───────────────┬────────────────┐
#> │ values ┆ number_of_twos │
#> │ --- ┆ --- │
#> │ array[i64, 2] ┆ u32 │
#> ╞═══════════════╪════════════════╡
#> │ [1, 2] ┆ 1 │
#> │ [1, 1] ┆ 0 │
#> │ [2, 2] ┆ 2 │
#> └───────────────┴────────────────┘