* Concat data along rows * @param dfList Array * @param axis Array * @returns DataFrame
(dfList: Array<DataFrame | Series>, axis: number )
| 71 | * @returns DataFrame |
| 72 | */ |
| 73 | function processRow(dfList: Array<DataFrame | Series>, axis: number ): DataFrame | Series { |
| 74 | let allDf: any = {} |
| 75 | let maxLen = 0 |
| 76 | for (let i=0; i < dfList.length; i++) { |
| 77 | let df = dfList[i] |
| 78 | let columns = df.columns |
| 79 | let columnData: ArrayType2D; |
| 80 | if ( df instanceof DataFrame) { |
| 81 | columnData = df.getColumnData as ArrayType2D |
| 82 | } else { |
| 83 | columnData = [df.values] as ArrayType2D |
| 84 | } |
| 85 | |
| 86 | |
| 87 | if (i ===0) { |
| 88 | for(let j=0; j < columns.length; j++) { |
| 89 | let column = columns[j] |
| 90 | let colData = columnData[j] |
| 91 | allDf[column] = colData |
| 92 | } |
| 93 | } else { |
| 94 | let nonColumn = Object.keys(allDf).filter( (key:any) =>{ |
| 95 | return !columns.includes(key) |
| 96 | }) |
| 97 | |
| 98 | for(let j=0; j < columns.length; j++) { |
| 99 | let column = columns[j] |
| 100 | let colData = columnData[j] |
| 101 | if (Object.keys(allDf).includes(column)) { |
| 102 | allDf[column].push(...colData) |
| 103 | } |
| 104 | else { |
| 105 | let residualArray = new Array(maxLen).fill(NaN) |
| 106 | residualArray.push(...colData) |
| 107 | allDf[column] = residualArray |
| 108 | } |
| 109 | } |
| 110 | if (nonColumn.length > 0) { |
| 111 | let currentDfLen = columnData[0].length |
| 112 | for( let j=0; j < nonColumn.length; j++) { |
| 113 | let column = nonColumn[j] |
| 114 | let residualArray = new Array(currentDfLen).fill(NaN) |
| 115 | allDf[column].push(...residualArray) |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | maxLen += columnData[0].length |
| 120 | } |
| 121 | |
| 122 | if (Object.keys(allDf).length === 1) { |
| 123 | return new Series(Object.values(allDf)[0]) |
| 124 | } |
| 125 | return new DataFrame(allDf) |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Concatenate pandas objects along a particular axis. |