polars.Expr.bin.reinterpret#
- Expr.bin.reinterpret(
- *,
- dtype: PolarsDataType | DataTypeExpr,
- endianness: Endianness = 'little',
Interpret bytes as another type.
Supported types are numerical or temporal dtypes, or an
Arrayof these dtypes.- 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 rows of the binary array where the length does not match the size in bytes of the output array (number of items * byte size of item) will become NULL.
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 │ └─────────────────────┴─────────┘