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

Method head

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

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

copyMethod · 0.95
ilocMethod · 0.95

Tested by

no test coverage detected