Get the size of binary values in the given unit
Description
Get the size of binary values in the given unit
Usage
<Expr>$bin$size(unit = "b")
Arguments
unit
|
Scale the returned size to the given unit. Can be “b” ,
“kb” , “mb” , “gb” ,
“tb” , or their full names (“kilobytes” , etc.).
|
Value
Expr of data type UInt or Float.
Examples
library("polars")
df = pl$DataFrame(
name = c("black", "yellow", "blue"),
code_hex = as_polars_series(c("000000", "ffff00", "0000ff"))$cast(pl$Binary)
)
df$with_columns(
n_bytes = pl$col("code_hex")$bin$size(),
n_kilobytes = pl$col("code_hex")$bin$size("kb")
)
#> shape: (3, 4)
#> ┌────────┬───────────┬─────────┬─────────────┐
#> │ name ┆ code_hex ┆ n_bytes ┆ n_kilobytes │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ str ┆ binary ┆ u32 ┆ f64 │
#> ╞════════╪═══════════╪═════════╪═════════════╡
#> │ black ┆ b"000000" ┆ 6 ┆ 0.005859 │
#> │ yellow ┆ b"ffff00" ┆ 6 ┆ 0.005859 │
#> │ blue ┆ b"0000ff" ┆ 6 ┆ 0.005859 │
#> └────────┴───────────┴─────────┴─────────────┘