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

Method nUnique

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

* Return the number of unique elements in a column, across the specified axis. * To get the values use `.unique()` instead. * @param axis The axis to count unique elements across. Defaults to 1 * @example * ``` * const df = new DataFrame([[1, 2], [3, 4], [1, 2], [5, 6]], {

(axis: 0 | 1 = 1)

Source from the content-addressed store, hash-verified

2907 *
2908 */
2909 nUnique(axis: 0 | 1 = 1): Series {
2910 if ([0, 1].indexOf(axis) === -1) {
2911 throw Error(`ParamError: axis must be 0 or 1`);
2912 }
2913 const data = this.$getDataArraysByAxis(axis)
2914 const newData = data.map(row => new Set(row).size)
2915
2916 if (axis === 0) {
2917 return new Series(newData, {
2918 index: [...this.columns],
2919 dtypes: ["int32"]
2920 })
2921 } else {
2922 return new Series(newData, {
2923 index: [...this.index],
2924 dtypes: ["int32"]
2925 })
2926 }
2927 }
2928
2929 /**
2930 * Renames a column or index to specified value.

Callers

nothing calls this directly

Calls 3

$getDataArraysByAxisMethod · 0.95
indexOfMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected