polars.Expr.bin.encode#

Expr.bin.encode(encoding: TransferEncoding) Expr[source]#

Encode a value using the provided encoding.

Parameters:
encoding{‘hex’, ‘base64’}

The encoding to use.

Returns:
Expr

Expression of data type String with values encoded using provided encoding.

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.encode("hex").alias("code_encoded_hex"),
... )
shape: (3, 3)
┌────────┬─────────────────┬──────────────────┐
│ name   ┆ code            ┆ code_encoded_hex │
│ ---    ┆ ---             ┆ ---              │
│ str    ┆ binary          ┆ str              │
╞════════╪═════════════════╪══════════════════╡
│ black  ┆ b"\x00\x00\x00" ┆ 000000           │
│ yellow ┆ b"\xff\xff\x00" ┆ ffff00           │
│ blue   ┆ b"\x00\x00\xff" ┆ 0000ff           │
└────────┴─────────────────┴──────────────────┘