MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / sample

Method sample

src/danfojs-base/core/frame.ts:578–591  ·  view source on GitHub ↗

* Gets n number of random rows in a dataframe. Sample is reproducible if seed is provided. * @param num The number of rows to return. Default to 5. * @param options.seed An integer specifying the random seed that will be used to create the distribution. * @example * ``` * co

(num = 5, options?: { seed?: number })

Source from the content-addressed store, hash-verified

576 * ```
577 */
578 async sample(num = 5, options?: { seed?: number }): Promise<DataFrame> {
579 const { seed } = { seed: 1, ...options }
580
581 if (num > this.shape[0]) {
582 throw new Error("ParamError: Sample size cannot be bigger than number of rows");
583 }
584 if (num <= 0) {
585 throw new Error("ParamError: Sample size cannot be less than 1");
586 }
587
588 const shuffledIndex = await tensorflow.data.array(this.index).shuffle(num, `${seed}`).take(num).toArray();
589 const df = this.iloc({ rows: shuffledIndex });
590 return df;
591 }
592
593 /**
594 * Return Addition of DataFrame and other, element-wise (binary operator add).

Callers

nothing calls this directly

Calls 2

ilocMethod · 0.95
shuffleMethod · 0.80

Tested by

no test coverage detected