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