polars.Expr.bin.reinterpret#
- Expr.bin.reinterpret(
- *,
- dtype: PolarsDataType,
- endianness: Endianness = 'little',
Interpret a buffer as a numerical Polars type.
- Parameters:
- dtypePolarsDataType
Which type to interpret binary column into.
- endianness{“big”, “little”}, optional
Which endianness to use when interpreting bytes, by default “little”.
- Returns:
- Expr
Expression of data type
dtype
. Note that if binary array is too short value will be null. If binary array is too long, remainder will be ignored.
Examples
>>> df = pl.DataFrame({"data": [b"\x05\x00\x00\x00", b"\x10\x00\x01\x00"]}) >>> df.with_columns( ... bin2int=pl.col("data").bin.reinterpret( ... dtype=pl.Int32, endianness="little" ... ), ... ) shape: (2, 2) ┌─────────────────────┬─────────┐ │ data ┆ bin2int │ │ --- ┆ --- │ │ binary ┆ i32 │ ╞═════════════════════╪═════════╡ │ b"\x05\x00\x00\x00" ┆ 5 │ │ b"\x10\x00\x01\x00" ┆ 65552 │ └─────────────────────┴─────────┘