* Returns the first n values in a Series * @param rows The number of rows to return * @example * ``` * const sf = new Series([1, 2, 3, 4, 5, 6], { index: ['a', 'b', 'c', 'd', 'e', 'f'] }); * const sf2 = sf.head(3); * sf2.print(); * ```
(rows: number = 5)
| 155 | * ``` |
| 156 | */ |
| 157 | head(rows: number = 5): Series { |
| 158 | if (rows <= 0) { |
| 159 | throw new Error("ParamError: Number of rows cannot be less than 1") |
| 160 | } |
| 161 | if (this.shape[0] <= rows) { |
| 162 | return this.copy() |
| 163 | } |
| 164 | if (this.shape[0] - rows < 0) { |
| 165 | throw new Error("ParamError: Number of rows cannot be greater than available rows in data") |
| 166 | } |
| 167 | return this.iloc([`0:${rows}`]) |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Returns the last n values in a Series |