polars.Expr.first#

Expr.first(*, ignore_nulls: bool = False) Expr[source]#

Get the first value.

Parameters:
ignore_nulls

Ignore null values (default False). If set to True, the first non-null value is returned, otherwise None is returned if no non-null value exists.

Examples

>>> df = pl.DataFrame({"a": [None, 1, 2]})
>>> df.select(pl.col("a").first())
shape: (1, 1)
┌──────┐
│ a    │
│ ---  │
│ i64  │
╞══════╡
│ null │
└──────┘
>>> df.select(pl.col("a").first(ignore_nulls=True))
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 1   │
└─────┘