Skip to content

Shuffle the contents of this expression

Description

Note this is shuffled independently of any other column or Expression. If you want each row to stay the same use df$sample(shuffle = TRUE).

Usage

<Expr>$shuffle(seed = NULL)

Arguments

seed Integer indicating the seed for the random number generator. If NULL (default), a random seed is generated each time the shuffle is called.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = 1:3)
df$with_columns(
  shuffled = pl$col("a")$shuffle(seed = 1)
)
#> shape: (3, 2)
#> ┌─────┬──────────┐
#> │ a   ┆ shuffled │
#> │ --- ┆ ---      │
#> │ i32 ┆ i32      │
#> ╞═════╪══════════╡
#> │ 1   ┆ 2        │
#> │ 2   ┆ 1        │
#> │ 3   ┆ 3        │
#> └─────┴──────────┘