polars.Expr.arr.contains#
- Expr.arr.contains( ) Expr [source]#
Check if sub-arrays contain the given item.
- Parameters:
- item
Item that will be checked for membership
- Returns:
- Expr
Expression of data type
Boolean
.
Examples
>>> df = pl.DataFrame( ... {"a": [["a", "b"], ["x", "y"], ["a", "c"]]}, ... schema={"a": pl.Array(pl.String, 2)}, ... ) >>> df.with_columns(contains=pl.col("a").arr.contains("a")) shape: (3, 2) ┌───────────────┬──────────┐ │ a ┆ contains │ │ --- ┆ --- │ │ array[str, 2] ┆ bool │ ╞═══════════════╪══════════╡ │ ["a", "b"] ┆ true │ │ ["x", "y"] ┆ false │ │ ["a", "c"] ┆ true │ └───────────────┴──────────┘