Check if values start with a binary substring
Description
Check if values start with a binary substring
Usage
<Expr>$bin$starts_with(sub)
Arguments
sub
|
Prefix substring. |
Value
Expr returing a Boolean
Examples
library("polars")
colors = pl$DataFrame(
name = c("black", "yellow", "blue"),
code = as_polars_series(c("x00x00x00", "xffxffx00", "x00x00xff"))$cast(pl$Binary),
prefix = as_polars_series(c("x00", "xffx00", "xffxff"))$cast(pl$Binary)
)
colors$select(
"name",
starts_with_lit = pl$col("code")$bin$starts_with("xff"),
starts_with_expr = pl$col("code")$bin$starts_with(pl$col("prefix"))
)
#> shape: (3, 3)
#> ┌────────┬─────────────────┬──────────────────┐
#> │ name ┆ starts_with_lit ┆ starts_with_expr │
#> │ --- ┆ --- ┆ --- │
#> │ str ┆ bool ┆ bool │
#> ╞════════╪═════════════════╪══════════════════╡
#> │ black ┆ false ┆ true │
#> │ yellow ┆ true ┆ false │
#> │ blue ┆ false ┆ false │
#> └────────┴─────────────────┴──────────────────┘