polars.Expr.is_first#

Expr.is_first() Self[source]#

Get a mask of the first unique value.

Returns:
Expr

Expression of data type Boolean.

Examples

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