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

Method mean

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

* Return mean of DataFrame across specified axis. * @param options.axis 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 * @example * ``` * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B'] }) * df.mean().print() * ``` * @exa

(options?: { axis?: 0 | 1 })

Source from the content-addressed store, hash-verified

828 * ```
829 */
830 mean(options?: { axis?: 0 | 1 }): Series {
831 const { axis } = { axis: 1, ...options }
832
833 if (this.$frameIsNotCompactibleForArithmeticOperation()) {
834 throw Error("TypeError: mean operation is not supported for string dtypes");
835 }
836
837 if ([0, 1].indexOf(axis) === -1) {
838 throw Error("ParamError: Axis must be 0 or 1");
839 }
840
841 const newData = this.$getDataByAxisWithMissingValuesRemoved(axis)
842 const resultArr = newData.map(arr => arr.reduce((a, b) => a + b, 0) / arr.length)
843 if (axis === 0) {
844 return new Series(resultArr, { index: this.columns });
845 } else {
846 return new Series(resultArr, { index: this.index });
847 }
848 }
849
850 /**
851 * Return median of DataFrame across specified axis.

Callers

nothing calls this directly

Calls 4

indexOfMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected