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

Method toString

src/danfojs-base/core/frame.ts:425–512  ·  view source on GitHub ↗

* Prints DataFrame to console as a formatted grid of row and columns.

()

Source from the content-addressed store, hash-verified

423 * Prints DataFrame to console as a formatted grid of row and columns.
424 */
425 toString(): string {
426 const maxRow = this.config.getMaxRow;
427 const maxColToDisplayInConsole = this.config.getTableMaxColInConsole;
428
429 // let data;
430 const dataArr: ArrayType2D = [];
431 const colLen = this.columns.length;
432
433 let header = [];
434
435 if (colLen > maxColToDisplayInConsole) {
436 //truncate displayed columns to fit in the console
437 let firstFourcolNames = this.columns.slice(0, 4);
438 let lastThreecolNames = this.columns.slice(colLen - 3);
439 //join columns with truncate ellipse in the middle
440 header = ["", ...firstFourcolNames, "...", ...lastThreecolNames];
441
442 let subIdx: Array<number | string>
443 let firstHalfValues: ArrayType2D
444 let lastHalfValueS: ArrayType2D
445
446 if (this.values.length > maxRow) {
447 //slice Object to show [max_rows]
448 let dfSubset1 = this.iloc({
449 rows: [`0:${maxRow}`],
450 columns: ["0:4"]
451 });
452
453 let dfSubset2 = this.iloc({
454 rows: [`0:${maxRow}`],
455 columns: [`${colLen - 3}:`]
456 });
457
458 subIdx = this.index.slice(0, maxRow);
459 firstHalfValues = dfSubset1.values as ArrayType2D
460 lastHalfValueS = dfSubset2.values as ArrayType2D
461
462 } else {
463 let dfSubset1 = this.iloc({ columns: ["0:4"] });
464 let dfSubset2 = this.iloc({ columns: [`${colLen - 3}:`] });
465
466 subIdx = this.index.slice(0, maxRow);
467 firstHalfValues = dfSubset1.values as ArrayType2D
468 lastHalfValueS = dfSubset2.values as ArrayType2D
469 }
470
471 // merge subset
472 for (let i = 0; i < subIdx.length; i++) {
473 const idx = subIdx[i];
474 const row = [idx, ...firstHalfValues[i], "...", ...lastHalfValueS[i]]
475 dataArr.push(row);
476 }
477
478 } else {
479 //display all columns
480 header = ["", ...this.columns]
481 let subIdx
482 let values: ArrayType2D

Callers

nothing calls this directly

Calls 2

ilocMethod · 0.95
sliceMethod · 0.80

Tested by

no test coverage detected