Skip to content

Commit 61f67b6

Browse files
authored
DOC: add unqiue value counts example to groupyby guide (#37847)
1 parent 336cc6c commit 61f67b6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

doc/source/user_guide/groupby.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,15 @@ index are the group names and whose values are the sizes of each group.
524524
525525
grouped.describe()
526526
527+
Another aggregation example is to compute the number of unique values of each group. This is similar to the ``value_counts`` function, except that it only counts unique values.
528+
529+
.. ipython:: python
530+
531+
ll = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]]
532+
df4 = pd.DataFrame(ll, columns=["A", "B"])
533+
df4
534+
df4.groupby("A")["B"].nunique()
535+
527536
.. note::
528537

529538
Aggregation functions **will not** return the groups that you are aggregating over

0 commit comments

Comments
 (0)