Skip to content

remove index column in SeriesGroupBy.nlargest #27894

Closed
@RainFung

Description

@RainFung

Code Sample, a copy-pastable example if possible

# Your code here
pdf = pd.DataFrame({
    'a': [1, 1, 1, 2, 2, 2, 3, 3, 3],
    'b': [1, 2, 2, 2, 3, 3, 3, 4, 4]}, columns=['a', 'b'])

pdf.groupby(['a'])['b'].nlargest(1)
a   
1  1    2
2  4    3
3  7    4
Name: b, dtype: int64

Problem description

It raise the index to column(1, 4, 7) above. But we dont need it most time.

Expected Output

pdf.groupby(['a'])['b'].nlargest(1)
a   
1     2
2    3
3    4

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.5.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: zh_CN.utf8
LANG: None
LOCALE: zh_CN.UTF-8

pandas: 0.24.2
pytest: 5.0.1
pip: 18.1
setuptools: 41.0.1
Cython: 0.29.10
numpy: 1.17.0
scipy: 1.1.0
pyarrow: 0.14.1
xarray: None
IPython: 7.2.0
sphinx: 2.1.2
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.5.1
numexpr: 2.6.9
feather: 0.4.0
matplotlib: 3.1.1
openpyxl: 2.6.1
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml.etree: 4.2.5
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.5
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions