Skip to content

Difference between count and nunique formatting #32463

@MathieuDutSik

Description

@MathieuDutSik

The count with groupby gives the number of entries while nunique gives the number of unique entries. The problem is that we get an additional column

>>> df = pd.DataFrame({"A": [0,0,1,1,0], "B": [1,2,3,4,5]})
>>> df.groupby("A").count()
   B
A   
0  3
1  2
>>> df.groupby("A").nunique()
   A  B
A      
0  1  3
1  1  2

Why is the A column being added in nunique output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Output-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions