Skip to content

BUG: groupby.describe on a frame with MultiIndex describes groupings #50804

Closed
@rhshadrach

Description

@rhshadrach
df1 = pd.DataFrame([[1, 2]], columns=["a", "b"])
gb1 = df1.groupby("a")
result1 = gb1.describe()
print(result1.to_string())
#       b                                  
#   count mean std  min  25%  50%  75%  max
# a                                        
# 1   1.0  2.0 NaN  2.0  2.0  2.0  2.0  2.0

columns = pd.MultiIndex.from_tuples(
    [("a", ""), ("b", "c")], names=["b", "c"]
)
df2 = pd.DataFrame([[1, 2]], columns=columns)
gb2 = df2.groupby("a")
result2 = gb2.describe()
print(result2.to_string())
# b     a                                       b                                  
# c                                             c                                  
#   count mean std  min  25%  50%  75%  max count mean std  min  25%  50%  75%  max
# a                                                                                
# 1   1.0  1.0 NaN  1.0  1.0  1.0  1.0  1.0   1.0  2.0 NaN  2.0  2.0  2.0  2.0  2.0

In the first case, the grouping a is not included in the results; in the second case the grouping a is. The grouping should not be described here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions