* Return the sum of values across an axis. * @param options.axis 0 or 1. If 0, count column-wise, if 1, add row-wise. Defaults to 1 * @example * ``` * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']}) * df.sum().print() * ``` * * @example
(options?: { axis?: 0 | 1 })
| 1337 | * ``` |
| 1338 | */ |
| 1339 | sum(options?: { axis?: 0 | 1 }): Series { |
| 1340 | const { axis } = { axis: 1, ...options } |
| 1341 | |
| 1342 | if ([0, 1].indexOf(axis) === -1) { |
| 1343 | throw Error("ParamError: Axis must be 0 or 1"); |
| 1344 | } |
| 1345 | |
| 1346 | const result = this.$getDataByAxisWithMissingValuesRemoved(axis) |
| 1347 | const sumArr = result.map((innerArr) => { |
| 1348 | return innerArr.reduce((a, b) => Number(a) + Number(b), 0) |
| 1349 | }) |
| 1350 | if (axis === 0) { |
| 1351 | return new Series(sumArr, { |
| 1352 | index: [...this.columns] |
| 1353 | }) |
| 1354 | } else { |
| 1355 | return new Series(sumArr, { |
| 1356 | index: [...this.index] |
| 1357 | }) |
| 1358 | } |
| 1359 | |
| 1360 | } |
| 1361 | |
| 1362 | /** |
| 1363 | * Return percentage difference of DataFrame with other. |
nothing calls this directly
no test coverage detected