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

Method mode

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

* Return mode of DataFrame across specified axis. * @param options.axis 0 or 1. If 0, compute the mode column-wise, if 1, row-wise. Defaults to 1 * @param options.keep If there are more than one modes, returns the mode at position [keep]. Defaults to 0 * @example * ``` * con

(options?: { axis?: 0 | 1, keep?: number })

Source from the content-addressed store, hash-verified

893 * ```
894 */
895 mode(options?: { axis?: 0 | 1, keep?: number }): Series {
896 const { axis, keep } = { axis: 1, keep: 0, ...options }
897
898 if (this.$frameIsNotCompactibleForArithmeticOperation()) {
899 throw Error("TypeError: mode operation is not supported for string dtypes");
900 }
901
902 if ([0, 1].indexOf(axis) === -1) {
903 throw Error("ParamError: Axis must be 0 or 1");
904 }
905
906 const newData = this.$getDataByAxisWithMissingValuesRemoved(axis)
907 const resultArr = newData.map(arr => {
908 const tempMode = mode(arr)
909 if (tempMode.length === 1) {
910 return tempMode[0]
911 } else {
912 return tempMode[keep]
913 }
914 })
915 if (axis === 0) {
916 return new Series(resultArr, { index: this.columns });
917 } else {
918 return new Series(resultArr, { index: this.index });
919 }
920
921 }
922
923 /**
924 * Return minimum of values in a DataFrame across specified axis.

Callers

nothing calls this directly

Calls 4

indexOfMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected