polars.Expr.bin.slice#
- Expr.bin.slice(offset: int | IntoExpr, length: int | IntoExpr | None = None) Expr[source]#
Slice the binary values.
- Parameters:
- offset
Start index. Negative indexing is supported.
- length
Length of the slice. If set to
None(default), the slice is taken to the end of the value.
- Returns:
- Expr
Expression of data type
Binary.
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.slice(1, 2).alias("sliced"), ... ) shape: (3, 3) ┌────────┬─────────────────┬─────────────┐ │ name ┆ code ┆ sliced │ │ --- ┆ --- ┆ --- │ │ 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" │ └────────┴─────────────────┴─────────────┘