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
Node
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()
Browser
Output
Output
╔═══╤══════════════════════╗
║ │ 0 ║
╟───┼──────────────────────╢
║ A │ 3 ║
╟───┼──────────────────────╢
║ B │ 4 ║
╟───┼──────────────────────╢
║ C │ 2 ║
╟───┼──────────────────────╢
║ D │ 3 ║
╚═══╧══════════════════════╝

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

Node
Browser
Node
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()
Browser
Output
Output
╔═══╤══════════════════════╗
║ │ 0 ║
╟───┼──────────────────────╢
║ 0 │ 4 ║
╟───┼──────────────────────╢
║ 1 │ 4 ║
╟───┼──────────────────────╢
║ 2 │ 4 ║
╟───┼──────────────────────╢
║ 3 │ 4 ║
╚═══╧══════════════════════╝

Note: To get the unique elements along an axis, use DataFrame.unique.