pandas.api.typing.SeriesGroupBy.sample
pandas 3.1.1 · GroupBy · method
Randomly select rows, entries or columns. Set random_state for repeatable results.
Call syntax
pd.api.typing.SeriesGroupBy.sample(
n=None,
frac=None,
replace=False,
weights=None,
random_state=None,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
n |
Optional Positional or keyword Default None |
int Choose how many entries or positions to use. |
frac |
Optional Positional or keyword Default None |
float Set the fraction of the input to sample. |
replace |
Optional Positional or keyword Default False |
bool Choose whether the same entry can be sampled multiple times. |
weights |
Optional Positional or keyword Default None |
list-like Supply values representing relative importance for sampling or calculation. |
random_state |
Optional Positional or keyword Default None |
int, array-like, BitGenerator, np.random.RandomState, np.random.Generator Supply a seed or random generator to make sampling reproducible. |
Returns
Series or DataFrame