-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
result from groupby / nlargest with data frame with one row does not include the groupby key in the resulting index #16345
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
this is a filtering method, like head, so this is expected.
|
though it should have the group-and column though. |
actually, this appears to work.
|
The problem occurs when the data frame contains only one row (see example above). In that case, the "animal" column disappears. |
A slight generalization on the recreate also exhibits the "group dropping" behavior despite having multiple rows in the output. Worth confirming any fix covers this situation too. Observed:
Expected: group column is retained in Out[4]. |
Hi, @jreback @mroeschke I looked into this a bit. I found the reason, why the column is dropped sometimes and sometimes not. For functions like nlarges and apply (not head) the column is always dropped, if the input If we do something like: ``
`` Should the resulting
the desired output? Similar question: If we execute ``
`` should the output
or should the column A be part of the I would really appreciate an answert about the output format of these two functions. Depending on that I may have found a way to fix this issue and the issues related with this (#29129 for example). If the columns should not be part of the Thanks very much. |
@phofl - transformers should return the index of the original DataFrame. |
Code Sample, a copy-pastable example if possible
Problem description
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.3.final.0
python-bits: 64
OS: Linux
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: None
statsmodels: None
xarray: None
IPython: 6.0.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.5.3
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: