-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
GroupBy(axis=1) Does Not Offer Implicit Selection By Columns Name(s) #27614
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
Comments
What do you mean by crash? This gives a KeyError for Note we also don't support Python2 anymore |
The example that @lebigot shows, should return the same as >>> df.T.groupby(by="x").sum().T # same as df.groupby(by="x", axis=1).sum()
x 10 20
y
0 2 4
1 10 12
0 18 20 Seems like a bug in groupby to me. @lebigot if you'd want to investigate, that'd be great. |
Hmm I think this example is somewhat confusing since I guess |
I've never understood So I see this as bug, given that |
Right there's some special casing going on for index names which I doubt is extended to column names. Might be somewhere around here: pandas/pandas/core/groupby/grouper.py Line 570 in 6e28b67
I think could logically extend for axis=1 to look at column names as well (in italics to disambiguate from labels) |
Code Sample, a copy-pastable example if possible
Problem description
The exception at the end is surprising: the intent is clearly to group by columns, on the "x" column label.
Furthermore, the documentation for
groupby()
seems to confirm this, as it states for the "by" argument that "A str or list of strs may be passed to group by the columns inself
".Expected Output
A dataframe with index [0, 1, 0] but grouped (and summed) columns [10, 20].
I wasn't able to test with the latest Pandas version, sorry!
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.32-642.15.1.el6.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.21.1
pytest: 3.2.3
pip: 9.0.1
setuptools: 28.8.0
Cython: 0.27.3
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: 0.8.2
IPython: 5.1.0
sphinx: 1.4.4
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.5
feather: None
matplotlib: 2.1.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.2.18
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: