polars.Expr.bin.tail#
- Expr.bin.tail(n: int | IntoExpr = 5) Expr[source]#
Take the last
nbytes of the binary values.- Parameters:
- n
Length of the slice (integer or expression). Negative indexing is supported; see note (2) below.
- Returns:
- Expr
Expression of data type
Binary.
Notes
A similar method exists for taking the first
nbytes:head().If
nis negative, it is interpreted as “starting at the nth byte”, e.g.,tail(-3)returns all but the first three bytes.
Examples
>>> colors = pl.DataFrame( ... { ... "name": ["black", "yellow", "blue"], ... "code": [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"], ... } ... ) >>> colors.with_columns( ... pl.col("code").bin.tail(2).alias("tail"), ... ) shape: (3, 3) ┌────────┬─────────────────┬─────────────┐ │ name ┆ code ┆ tail │ │ --- ┆ --- ┆ --- │ │ str ┆ binary ┆ binary │ ╞════════╪═════════════════╪═════════════╡ │ black ┆ b"\x00\x00\x00" ┆ b"\x00\x00" │ │ yellow ┆ b"\xff\xff\x00" ┆ b"\xff\x00" │ │ blue ┆ b"\x00\x00\xff" ┆ b"\x00\xff" │ └────────┴─────────────────┴─────────────┘