polars.Expr.bin.size#
- Expr.bin.size(unit: SizeUnit = 'b') Expr [source]#
Get the size of binary values in the given unit.
- Parameters:
- unit{‘b’, ‘kb’, ‘mb’, ‘gb’, ‘tb’}
Scale the returned size to the given unit.
- Returns:
- Expr
Expression of data type
UInt32
orFloat64
.
Examples
>>> from os import urandom >>> df = pl.DataFrame({"data": [urandom(n) for n in (512, 256, 1024)]}) >>> df.with_columns( ... n_bytes=pl.col("data").bin.size(), ... n_kilobytes=pl.col("data").bin.size("kb"), ... ) shape: (4, 3) ┌─────────────────────────────────┬─────────┬─────────────┐ │ data ┆ n_bytes ┆ n_kilobytes │ │ --- ┆ --- ┆ --- │ │ binary ┆ u32 ┆ f64 │ ╞═════════════════════════════════╪═════════╪═════════════╡ │ b"y?~B\x83\xf4V\x07\xd3\xfb\xb… ┆ 512 ┆ 0.5 │ │ b"\xee$4@f\xc14\x07\x8e\x88\x1… ┆ 256 ┆ 0.25 │ │ b"\x80\xbd\xb9nEq;2\x99$\xf9\x… ┆ 1024 ┆ 1.0 │ └─────────────────────────────────┴─────────┴─────────────┘