Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 1.87 KB

series.sample.md

File metadata and controls

64 lines (50 loc) · 1.87 KB
description
Returns a random sample of items from an axis of object.

Series.sample

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()

{% tabs %} {% tab title="Output" %}

╔═══╤════╗
 2  3  
╟───┼────╢
 4  5  
╟───┼────╢
 0  1  
╟───┼────╢
 7  40 
╟───┼────╢
 6  30 
╚═══╧════╝

{% endtab %} {% endtabs %}

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()