polars.Expr.repeat_by¶
- Expr.repeat_by(by: Union[polars.internals.expr.Expr, str]) polars.internals.expr.Expr ¶
Repeat the elements in this Series n times by dictated by the number given by by. The elements are expanded into a List
- Parameters
- 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.
- Returns
- Series of type List
Examples
>>> df = pl.DataFrame( ... { ... "a": ["x", "y", "z"], ... "n": [1, 2, 3], ... } ... ) >>> df.select(pl.col("a").repeat_by("n")) shape: (3, 1) ┌─────────────────┐ │ a │ │ --- │ │ list [str] │ ╞═════════════════╡ │ ["x"] │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ ["y", "y"] │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ ["z", "z", "z"] │ └─────────────────┘