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

Method head

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

* Returns the first n values in a DataFrame * @param rows The number of rows to return * @example * ``` * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']}) * const df2 = df.head(1) * ```

(rows: number = 5)

Source from the content-addressed store, hash-verified

521 * ```
522 */
523 head(rows: number = 5): DataFrame {
524
525 if (rows <= 0) {
526 throw new Error("ParamError: Number of rows cannot be less than 1")
527 }
528 if (this.shape[0] <= rows) {
529 return this.copy()
530 }
531 if (this.shape[0] - rows < 0) {
532 throw new Error("ParamError: Number of rows cannot be greater than available rows in data")
533 }
534
535 return this.iloc({ rows: [`0:${rows}`] })
536 }
537
538 /**
539 * Returns the last n values in a DataFrame

Callers

nothing calls this directly

Calls 2

copyMethod · 0.95
ilocMethod · 0.95

Tested by

no test coverage detected