* 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)
| 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. |
nothing calls this directly
no test coverage detected