DataFrame.unique

Return unique values of DataFrame along an axis. Uniques are returned in order of appearance. Set-based unique, therefore does NOT sort.

danfo.DataFrame.unique(axis) [source]

Parameters

Type

Description

Default

axis

Int

0 for row axis, and 1 for column axis

1

Returns:

return Object

Examples

Return 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)
console.log(df.unique()) //defaults to axis 1
Browser
Output
Output
{
A: [ -20, 30, 47.3 ],
B: [ 34, -4, 5, 6 ],
C: [ 20, 30 ],
D: [ 'a', 'b', 'c' ]
}

Return 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)
console.log(df.unique(axis=0));
Browser
Output
Output
{
'0': [ -20, 34, 20, 'a' ],
'1': [ 30, -4, 20, 'b' ],
'2': [ 47.3, 5, 30, 'c' ],
'3': [ -20, 6, 30, 'c' ]
}

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