* Returns the last 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.tail(3); * sf2.print(); * ```
(rows: number = 5)
| 178 | * ``` |
| 179 | */ |
| 180 | tail(rows: number = 5): Series { |
| 181 | if (rows <= 0) { |
| 182 | throw new Error("ParamError: Number of rows cannot be less than 1") |
| 183 | } |
| 184 | if (this.shape[0] <= rows) { |
| 185 | return this.copy() |
| 186 | } |
| 187 | if (this.shape[0] - rows < 0) { |
| 188 | throw new Error("ParamError: Number of rows cannot be greater than available rows in data") |
| 189 | } |
| 190 | |
| 191 | const startIdx = this.shape[0] - rows |
| 192 | return this.iloc([`${startIdx}:`]) |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Returns specified number of random rows in a Series |