result from groupby / nlargest with data frame with one row does not include the groupby key in the resulting index · Issue #16345 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
In [1]: df = pandas.DataFrame([["Dog", 1], ["Dog", 2]], columns=["animal", "value"])
In [2]: df.groupby("animal").value.nlargest(5)
Out[2]:
animal
Dog 1 2
0 1
Name: value, dtype: int64
In [3]: df = pandas.DataFrame([["Dog", 1]], columns=["animal", "value"])
In [4]: df.groupby("animal").value.nlargest(5)
Out[4]:
0 1
Name: value, dtype: int64
Problem description
Expected Output
In [3]: df = pandas.DataFrame([["Dog", 1]], columns=["animal", "value"]) In [4]: df.groupby("animal").value.nlargest(5) Out[4]: animal Dog 0 1 Name: value, dtype: int64
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