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

Method tail

src/danfojs-base/core/series.ts:180–193  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

copyMethod · 0.95
ilocMethod · 0.95

Tested by

no test coverage detected