MCPcopy Create free account
hub / github.com/javascriptdata/danfojs / generateKeyCombination

Method generateKeyCombination

src/danfojs-base/transformers/merge.ts:93–117  ·  view source on GitHub ↗

* Generate key combination base on the columns we want to merge on * e.g df = { * key1: ["KO", "K0", "K3", "K4"], * Key2: ["K1", "K1", "K3", "K5"], * A: [1,2,3,4] * B: [3,4,5,6] * } * keycomb = generateKeyCombination(df.values, [0,1]) * This should output * { * '

(values: ArrayType2D, colIndex: ArrayType1D)

Source from the content-addressed store, hash-verified

91 * @param colIndex
92 */
93 private generateKeyCombination(values: ArrayType2D, colIndex: ArrayType1D): keyComb {
94 let colKeyComb: keyComb = {}
95
96 for (let i=0; i < values.length; i++) {
97 let rowValues = values[i]
98 let rowKeyCombValues = [];
99 for (let j =0; j < colIndex.length; j++) {
100 let index = colIndex[j] as number
101 rowKeyCombValues.push(rowValues[index])
102 }
103 let rowKeyComb = rowKeyCombValues.join('_')
104 let otherValues = rowValues.filter((val, index) => {
105 return !colIndex.includes(index)
106 })
107 if (utils.keyInObject(colKeyComb, rowKeyComb)) {
108 colKeyComb[rowKeyComb].filters.push(otherValues)
109 } else {
110 colKeyComb[rowKeyComb] = {
111 filters: [otherValues],
112 combValues: rowKeyCombValues
113 }
114 }
115 }
116 return colKeyComb
117 }
118
119 /**
120 * Generate columns for the newly generated merged DataFrame

Callers 1

operationMethod · 0.95

Calls 3

joinMethod · 0.80
includesMethod · 0.80
keyInObjectMethod · 0.80

Tested by

no test coverage detected