Skip to content

aggregate the dataframe according to the multi-layer in the axis=1 does not work! #46995

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
1 of 3 tasks
CatNofishing opened this issue May 11, 2022 · 3 comments · Fixed by #47078
Closed
1 of 3 tasks
Labels
Bug Duplicate Report Duplicate issue or pull request Groupby Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@CatNofishing
Copy link

CatNofishing commented May 11, 2022

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

df=pd.DataFrame(np.random.rand(6,6))
df.columns=pd.MultiIndex.from_product([['b','c'],[1,2,3]])
df.groupby(level=0,axis=1).agg(['mean','max'])

Issue Description

I tried to aggregate the dataframe according to the multi-layer index in the axis = 1 direction, but it failed.
image

Expected Behavior

I expect result is
image

Installed Versions

INSTALLED VERSIONS

commit : db08276
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Chinese (Simplified)_China.936

pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : 0.29.21
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.30.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : 5.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.3.20
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.51.2

@CatNofishing CatNofishing added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 11, 2022
@simonjayhawkins
Copy link
Member

Thanks @CatNofishing for the report.

This gives a result in a pandas 1.3 onwards, but the result looks iffy, so this could be related to #46904

Closing this issue. Feel free to open a new issue using a newer release of pandas.

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 12, 2022
@rhshadrach
Copy link
Member

Agreed - this is a duplicate of #46904. The result here is incorrect and this should raise instead.

@rhshadrach
Copy link
Member

While the core issue is the same, it is possible to close #46904 without fixing this issue. I'm reopening to ensure it's closed appropriately.

@rhshadrach rhshadrach reopened this May 19, 2022
@rhshadrach rhshadrach added Groupby Regression Functionality that used to work in a prior pandas version labels May 19, 2022
@rhshadrach rhshadrach added this to the 1.4.3 milestone May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Groupby Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants