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

Method median

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

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

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

Source from the content-addressed store, hash-verified

857 * ```
858 */
859 median(options?: { axis?: 0 | 1 }): Series {
860 const { axis } = { axis: 1, ...options }
861
862 if (this.$frameIsNotCompactibleForArithmeticOperation()) {
863 throw Error("TypeError: median operation is not supported for string dtypes");
864 }
865
866 if ([0, 1].indexOf(axis) === -1) {
867 throw Error("ParamError: Axis must be 0 or 1");
868 }
869
870 const newData = this.$getDataByAxisWithMissingValuesRemoved(axis)
871 const resultArr = newData.map(arr => median(arr))
872 if (axis === 0) {
873 return new Series(resultArr, { index: this.columns });
874 } else {
875 return new Series(resultArr, { index: this.index });
876 }
877
878 }
879
880 /**
881 * Return mode of DataFrame across specified axis.

Callers

nothing calls this directly

Calls 4

indexOfMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected