pandas 1.4.2

ParametersReturns
nunique(self, dropna: 'bool' = True) -> 'DataFrame'

Parameters

dropna : bool, default True

Don't include NaN in the counts.

Returns

nunique: DataFrame

Return DataFrame with counts of unique elements in each position.

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({'id': ['spam', 'egg', 'egg', 'spam',
...  'ham', 'ham'],
...  'value1': [1, 5, 5, 2, 5, 5],
...  'value2': list('abbaxy')})
... df id value1 value2 0 spam 1 a 1 egg 5 b 2 egg 5 b 3 spam 2 a 4 ham 5 x 5 ham 5 y
This example is valid syntax, but we were not able to check execution
>>> df.groupby('id').nunique()
      value1  value2
id
egg        1       1
ham        1       2
spam       2       1

Check for rows with the same id but conflicting values:

This example is valid syntax, but we were not able to check execution
>>> df.groupby('id').filter(lambda g: (g.nunique() > 1).any())
     id  value1 value2
0  spam       1      a
3  spam       2      a
4   ham       5      x
5   ham       5      y
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/groupby/generic.py#1469
type: <class 'function'>
Commit: