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

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

Node
Browser
const dfd = require("danfojs-node")
let data = { "A": [-20, 30, 47.3, -20] ,
"B": [34, -4, 5, 6] ,
"C": [20, 20, 30, 30],
"D": ["a", "b", "c", "c"] }
let df = new dfd.DataFrame(data)
df.nUnique(axis=0).print()
Output
╔═══╤═══╗
║ A │ 3 ║
╟───┼───╢
║ B │ 4 ║
╟───┼───╢
║ C │ 2 ║
╟───┼───╢
║ D │ 3 ║
╚═══╧═══╝
Note: To get the unique elements along an axis, see DataFrame.unique.
Copy link
On this page
Examples
Return number of unique values along default axis (axis=1)
Return number of unique values in row axis (axis=0)