Powered By GitBook
Series.sample
Return a random sample of items from an axis of object.
danfo.Series.sample(num) [source]
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
1
const dfd = require("danfojs-node")
2
3
async function load_data() {
4
let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78];
5
let sf1 = new dfd.Series(data1);
6
let sample = await sf1.sample(5)
7
sample.print()
8
9
}
10
load_data()
Copied!
Output
1
╔═══╤════╗
2
23
3
╟───┼────╢
4
45
5
╟───┼────╢
6
01
7
╟───┼────╢
8
740
9
╟───┼────╢
10
630
11
╚═══╧════╝
Copied!

Specify a seed when sampling

1
const dfd = require("danfojs-node")
2
3
async function load_data() {
4
let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78];
5
let sf1 = new dfd.Series(data1);
6
let sample = await sf1.sample(5, { seed: 2 })
7
sample.print()
8
9
}
10
load_data()
11
Copied!
Last modified 24d ago