polars.Expr.sample
-
Sample from this expression.
- Parameters:
-
- n
-
Number of items to return. Cannot be used with
fraction. Defaults to 1 iffractionis None. - fraction
-
Fraction of items to return. Cannot be used with
n. - with_replacement
-
Allow values to be sampled more than once.
- shuffle
-
Determines the order of the sampled elements. If True, sampled elements are explicitly shuffled. If False, the relative order of the sampled elements is preserved. (i.e. they appear in the same order as the original input). If None (default), no ordering guarantee; uses the most performant algorithm.
- seed
-
Seed for the random number generator. If set to None (default), a random seed is generated for each sample operation.
Examples
>>> df = pl.DataFrame({"a": [1, 2, 3]}) >>> df.select( ... pl.col("a").sample( ... fraction=1.0, with_replacement=True, shuffle=False, seed=1 ... ) ... ) shape: (3, 1) ┌─────┐ │ a │ │ --- │ │ i64 │ ╞═════╡ │ 3 │ │ 3 │ │ 1 │ └─────┘
Expr.sample(
n: int | IntoExprColumn | None = None,
*,
fraction: float | IntoExprColumn | None = None,
with_replacement: bool = False,
shuffle: bool | None = None,
seed: int | None = None,
) → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.sample.html