Skip to content

Repeat values

Source code

Description

Repeat the elements in this Series as specified in the given expression. The repeated elements are expanded into a List.

Usage

<Expr>$repeat_by(by)

Arguments

by Expr that determines how often the values will be repeated. The column will be coerced to UInt32.

Value

Expr

Examples

library("polars")

df = pl$DataFrame(a = c("w", "x", "y", "z"), n = c(-1, 0, 1, 2))
df$with_columns(repeated = pl$col("a")$repeat_by("n"))
#> shape: (4, 3)
#> ┌─────┬──────┬────────────┐
#> │ a   ┆ n    ┆ repeated   │
#> │ --- ┆ ---  ┆ ---        │
#> │ str ┆ f64  ┆ list[str]  │
#> ╞═════╪══════╪════════════╡
#> │ w   ┆ -1.0 ┆ null       │
#> │ x   ┆ 0.0  ┆ []         │
#> │ y   ┆ 1.0  ┆ ["y"]      │
#> │ z   ┆ 2.0  ┆ ["z", "z"] │
#> └─────┴──────┴────────────┘