polars.Expr.list.contains#

Expr.list.contains(
item: float | str | bool | int | date | datetime | time | IntoExprColumn,
) Expr[source]#

检查子列表是否包含给定的项目。

Parameters:
item

将检查成员资格的项

Returns:
Expr

数据类型 Boolean 的表达式。

示例

>>> df = pl.DataFrame({"a": [[3, 2, 1], [], [1, 2]]})
>>> df.with_columns(contains=pl.col("a").list.contains(1))
shape: (3, 2)
┌───────────┬──────────┐
│ a         ┆ contains │
│ ---       ┆ ---      │
│ list[i64] ┆ bool     │
╞═══════════╪══════════╡
│ [3, 2, 1] ┆ true     │
│ []        ┆ false    │
│ [1, 2]    ┆ true     │
└───────────┴──────────┘