DataFrame.nUnique
Returns the number of unique elements in a column, across the specified axis.
danfo.DataFrame.nUnique(axis) [source]
Parameters
Type
Description
Default
axis
Int
0 for row axis, and 1 for column axis
1

Examples

Return number of unique values along default axis (axis=1)

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = { "A": [-20, 30, 47.3, -20] ,
4
"B": [34, -4, 5, 6] ,
5
"C": [20, 20, 30, 30],
6
"D": ["a", "b", "c", "c"] }
7
8
let df = new dfd.DataFrame(data)
9
df.nunique().print()
Copied!
1
Copied!
Output
1
╔═══╤═══╗
2
║ 0 │ 4 ║
3
╟───┼───╢
4
║ 1 │ 4 ║
5
╟───┼───╢
6
║ 2 │ 4 ║
7
╟───┼───╢
8
║ 3 │ 4 ║
9
╚═══╧═══╝
Copied!

Return number of unique values in row axis (axis=0)

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = { "A": [-20, 30, 47.3, -20] ,
4
"B": [34, -4, 5, 6] ,
5
"C": [20, 20, 30, 30],
6
"D": ["a", "b", "c", "c"] }
7
8
let df = new dfd.DataFrame(data)
9
df.nUnique(axis=0).print()
Copied!
1
Copied!
Output
1
╔═══╤═══╗
2
║ A │ 3 ║
3
╟───┼───╢
4
║ B │ 4 ║
5
╟───┼───╢
6
║ C │ 2 ║
7
╟───┼───╢
8
║ D │ 3 ║
9
╚═══╧═══╝
Copied!
Note: To get the unique elements along an axis, see DataFrame.unique.