polars.Expr.shuffle#

Expr.shuffle(seed: int | None = None, fixed_seed: bool = False) Self[source]#

Shuffle the contents of this expression.

Parameters:
seed

Seed for the random number generator. If set to None (default), a random seed is generated using the random module.

fixed_seed

If True, The seed will not be incremented between draws. This can make output predictable because draw ordering can change due to threads being scheduled in a different order.

Examples

>>> df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select(pl.col("a").shuffle(seed=1))
shape: (3, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 2   │
│ 1   │
│ 3   │
└─────┘