Skip to content

Latest commit

 

History

History
93 lines (76 loc) · 2 KB

dataframe.nunique-1.md

File metadata and controls

93 lines (76 loc) · 2 KB
description
Returns the number of unique elements in a column, across the specified axis.

DataFrame.nUnique

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)

{% tabs %} {% tab title="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()

{% endtab %}

{% tab title="Browser" %}

{% endtab %} {% endtabs %}

{% tabs %} {% tab title="Output" %}

╔═══╤═══╗
║ 0 │ 4 ║
╟───┼───╢
║ 1 │ 4 ║
╟───┼───╢
║ 2 │ 4 ║
╟───┼───╢
║ 3 │ 4 ║
╚═══╧═══╝

{% endtab %} {% endtabs %}

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

{% tabs %} {% tab title="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()

{% endtab %}

{% tab title="Browser" %}

{% endtab %} {% endtabs %}

{% tabs %} {% tab title="Output" %}

╔═══╤═══╗
║ A │ 3 ║
╟───┼───╢
║ B │ 4 ║
╟───┼───╢
║ C │ 2 ║
╟───┼───╢
║ D │ 3 ║
╚═══╧═══╝

{% endtab %} {% endtabs %}

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