polars sample for dataframe
Create sample dataframe.
Signature
> polars sample {flags}
Flags
-
--n-rows, -n {int}: Number of rows to be taken from dataframe. -
--fraction, -f {number}: Fraction of dataframe to be taken. -
--seed, -s {number}: Seed for the selection. -
--replace, -e: Sample with replace. -
--shuffle, -u: Shuffle sample.
Input/output types:
| input | output |
|---|---|
| polars_dataframe | polars_dataframe |
| polars_lazyframe | polars_lazyframe |
Examples
Sample rows from dataframe
> [[a b]; [1 2] [3 4]] | polars into-df | polars sample --n-rows 1
Shows sample row using fraction and replace
> [[a b]; [1 2] [3 4] [5 6]] | polars into-df | polars sample --fraction 0.5 --replace
Shows sample row using using predefined seed 1
> [[a b]; [1 2] [3 4] [5 6]] | polars into-df | polars sample --seed 1 --n-rows 1 ╭───┬───┬───╮ │ # │ a │ b │ ├───┼───┼───┤ │ 0 │ 5 │ 6 │ ╰───┴───┴───╯
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_sample.html