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

Method loadObjectIntoNdframe

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

* Internal function to format and load a Javascript object or object of arrays into NDFrame. * @param data Object or object of arrays. * @param type The type of the object. There are two recognized types: * * - type 1 object are in JSON format `[{a: 1, b: 2}, {a: 30, b: 20}]`.

({ data, type, index, columns, dtypes }: LoadObjectDataType)

Source from the content-addressed store, hash-verified

132 * @param dtypes Array of data types for each the column.
133 */
134 private loadObjectIntoNdframe({ data, type, index, columns, dtypes }: LoadObjectDataType): void {
135 if (type === 1 && Array.isArray(data)) {
136 const _data = (data).map((item) => {
137 return Object.values(item);
138 });
139
140 let _columnNames;
141
142 if (columns) {
143 _columnNames = columns
144 } else {
145 _columnNames = Object.keys((data)[0]);
146 }
147
148 this.loadArrayIntoNdframe({ data: _data, index, columns: _columnNames, dtypes });
149
150 } else {
151 const [_data, _colNames] = utils.getRowAndColValues(data);
152 let _columnNames;
153
154 if (columns) {
155 _columnNames = columns
156 } else {
157 _columnNames = _colNames
158 }
159 this.loadArrayIntoNdframe({ data: _data, index, columns: _columnNames, dtypes });
160 }
161 }
162
163 /**
164 * Converts and returns the data in the NDframe as a Tensorflow.js Tensor.

Callers 1

constructorMethod · 0.95

Calls 4

loadArrayIntoNdframeMethod · 0.95
getRowAndColValuesMethod · 0.80
mapMethod · 0.65
valuesMethod · 0.65

Tested by

no test coverage detected