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

Method tail

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

* Returns the last 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.tail(1) * ```

(rows: number = 5)

Source from the content-addressed store, hash-verified

545 * ```
546 */
547 tail(rows: number = 5): any {
548
549 if (rows <= 0) {
550 throw new Error("ParamError: Number of rows cannot be less than 1")
551 }
552 if (this.shape[0] <= rows) {
553 return this.copy()
554 }
555 if (this.shape[0] - rows < 0) {
556 throw new Error("ParamError: Number of rows cannot be greater than available rows in data")
557 }
558
559 rows = this.shape[0] - rows
560 return this.iloc({ rows: [`${rows}:`] })
561 }
562
563 /**
564 * Gets n number of random rows in a dataframe. Sample is reproducible if seed is provided.

Callers

nothing calls this directly

Calls 2

copyMethod · 0.95
ilocMethod · 0.95

Tested by

no test coverage detected