Repeat the elements in this Series as specified in the given expression
Description
The repeated elements are expanded into a List dtype.
Usage
<Expr>$repeat_by(by)
Arguments
by
|
Numeric column that determines how often the values will be repeated. The column will be coerced to UInt32. Give this dtype to make the coercion a no-op. Accepts expression input, strings are parsed as column names. |
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(a = c("x", "y", "z"), n = 1:3)
df$with_columns(
repeated = pl$col("a")$repeat_by("n")
)
#> shape: (3, 3)
#> ┌─────┬─────┬─────────────────┐
#> │ a ┆ n ┆ repeated │
#> │ --- ┆ --- ┆ --- │
#> │ str ┆ i32 ┆ list[str] │
#> ╞═════╪═════╪═════════════════╡
#> │ x ┆ 1 ┆ ["x"] │
#> │ y ┆ 2 ┆ ["y", "y"] │
#> │ z ┆ 3 ┆ ["z", "z", "z"] │
#> └─────┴─────┴─────────────────┘