MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / $setColumnNames

Method $setColumnNames

src/danfojs-base/core/generic.ts:311–339  ·  view source on GitHub ↗

* Internal function to set the column names for the NDFrame. This function * performs a check to ensure that the column names are unique, and same length as the * number of columns in the data.

(columns?: string[])

Source from the content-addressed store, hash-verified

309 * number of columns in the data.
310 */
311 $setColumnNames(columns?: string[]) {
312
313 // console.log(columns);
314 if (this.$isSeries) {
315 if (columns) {
316 if (this.$data.length != 0 && columns.length != 1 && typeof columns != 'string') {
317 ErrorThrower.throwColumnNamesLengthError(this, columns)
318 }
319 this.$columns = columns
320 } else {
321 this.$columns = ["0"]
322 }
323 } else {
324 if (columns) {
325
326 if (this.$data.length != 0 && columns.length != this.shape[1]) {
327
328 ErrorThrower.throwColumnNamesLengthError(this, columns)
329 }
330 if (Array.from(new Set(columns)).length !== columns.length) {
331 ErrorThrower.throwColumnDuplicateError()
332 }
333
334 this.$columns = columns
335 } else {
336 this.$columns = (utils.range(0, this.shape[1] - 1)).map((val) => `${val}`) //generate columns
337 }
338 }
339 }
340
341 /**
342 * Returns the shape of the NDFrame. Shape is determined by [row length, column length]

Callers 1

loadArrayIntoNdframeMethod · 0.95

Calls 2

mapMethod · 0.65
rangeMethod · 0.45

Tested by

no test coverage detected