polars.last#
- polars.last(*columns: str) Expr [source]#
Get the last value.
This function has different behavior depending on the input type:
None
-> Takes last column of a context (equivalent tocs.last()
).str
or[str,]
-> Syntactic sugar forpl.col(columns).last()
.
- Parameters:
- *columns
One or more column names. If set to
None
(default), returns an expression to take the last column of the context instead.
Examples
>>> df = pl.DataFrame( ... { ... "a": [1, 8, 3], ... "b": [4, 5, 2], ... "c": ["foo", "bar", "baz"], ... } ... ) >>> df.select(pl.last()) shape: (3, 1) ┌─────┐ │ c │ │ --- │ │ str │ ╞═════╡ │ foo │ │ bar │ │ baz │ └─────┘ >>> df.select(pl.last("a")) shape: (1, 1) ┌─────┐ │ a │ │ --- │ │ i64 │ ╞═════╡ │ 3 │ └─────┘ >>> df.select(pl.last("b", "c")) shape: (1, 2) ┌─────┬─────┐ │ b ┆ c │ │ --- ┆ --- │ │ i64 ┆ str │ ╞═════╪═════╡ │ 2 ┆ baz │ └─────┴─────┘