polars.Series.sample#
- Series.sample(
 - n: int | None = None,
 - *,
 - fraction: float | None = None,
 - with_replacement: bool = False,
 - shuffle: bool = False,
 - seed: int | None = None,
 Sample from this Series.
- 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
 Shuffle the order of sampled data points.
- seed
 Seed for the random number generator. If set to None (default), a random seed is generated for each sample operation.
Examples
>>> s = pl.Series("a", [1, 2, 3, 4, 5]) >>> s.sample(2, seed=0) shape: (2,) Series: 'a' [i64] [ 1 5 ]