Spec-Zone.ru › Polars

polars.DataFrame.sample

DataFrame.sample(
    n: int | Series | None = None,
    *,
    fraction: float | Series | None = None,
    with_replacement: bool = False,
    shuffle: bool | None = None,
    seed: int | None = None,
) → DataFrame

Sample from this DataFrame.

Parameters:
n

Number of items to return. Cannot be used with fraction. Defaults to 1 if fraction is 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 rows. If True, sampled rows are explicitly shuffled. If False, the relative order of the sampled rows is preserved. (i.e. they appear in the same order as the original DataFrame). 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 time the sample is called.

Examples

>>> df = pl.DataFrame(
...     {
...         "foo": [1, 2, 3],
...         "bar": [6, 7, 8],
...         "ham": ["a", "b", "c"],
...     }
... )
>>> df.sample(n=2, shuffle=False, seed=0)  
shape: (2, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ ham │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str │
╞═════╪═════╪═════╡
│ 3   ┆ 8   ┆ c   │
│ 2   ┆ 7   ┆ b   │
└─────┴─────┴─────┘

© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.sample.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API