Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rhshadrach opened this issue Jan 17, 2023 · 1 comment
Closed

Comments

@rhshadrach
Copy link
Member

rhshadrach commented Jan 17, 2023

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.

@rhshadrach
Copy link
Member Author

Closed by #50806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant