DataFrame.nunique
danfo.DataFrame.nunique(axis) [source]
Parameters
Type
Description
Default
axis
Int
0 for row axis, and 1 for column axis
1
Returns:
return Series

Examples

Return number of unique values along column 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()
10
Copied!
1
Copied!
Output
1
╔═══╤═══╗
2
║ 0 │ 3 ║
3
╟───┼───╢
4
║ 1 │ 4 ║
5
╟───┼───╢
6
║ 2 │ 2 ║
7
╟───┼───╢
8
║ 3 │ 3 ║
9
╚═══╧═══╝
10
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()
10
Copied!
1
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 0 │ 4 ║
5
╟───┼──────────────────────╢
6
║ 1 │ 4 ║
7
╟───┼──────────────────────╢
8
║ 2 │ 4 ║
9
╟───┼──────────────────────╢
10
║ 3 │ 4 ║
11
╚═══╧══════════════════════╝
Copied!
Note: To get the unique elements along an axis, use DataFrame.unique.
Last modified 17d ago