Series.sample
Returns a random sample of items from an axis of object.
danfo.Series.sample(num)
Parameters
Type
Description
Default
num
Int
The number of rows to return.
options
Object
seed: An integer specifying the random seed that will be used to create the distribution. Ensures reproducibility of generated samples.
{
seed: 1
}
Returns:
**** return {Promies} resolves to Series
Example
const dfd = require("danfojs-node")
async function sample_data() {
let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78];
let sf1 = new dfd.Series(data1);
let sample = await sf1.sample(5)
sample.print()
}
sample_data()
Output
╔═══╤════╗
23
╟───┼────╢
45
╟───┼────╢
01
╟───┼────╢
740
╟───┼────╢
630
╚═══╧════╝

Specify a seed when sampling

const dfd = require("danfojs-node")
async function sample_data() {
let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78];
let sf1 = new dfd.Series(data1);
let sample = await sf1.sample(5, { seed: 5 })
sample.print()
}
sample_data()
Copy link