polars.Expr.index_of#

Expr.index_of(element: IntoExpr) Expr[source]#

Get the index of the first occurrence of a value, or None if it’s not found.

Parameters:
element

Value to find.

Examples

>>> df = pl.DataFrame({"a": [1, None, 17]})
>>> df.select(
...     [
...         pl.col("a").index_of(17).alias("seventeen"),
...         pl.col("a").index_of(None).alias("null"),
...         pl.col("a").index_of(55).alias("fiftyfive"),
...     ]
... )
shape: (1, 3)
┌───────────┬──────┬───────────┐
│ seventeen ┆ null ┆ fiftyfive │
│ ---       ┆ ---  ┆ ---       │
│ u32       ┆ u32  ┆ u32       │
╞═══════════╪══════╪═══════════╡
│ 2         ┆ 1    ┆ null      │
└───────────┴──────┴───────────┘