Skip to content

remove index column in SeriesGroupBy.nlargest #27894

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
RainFung opened this issue Aug 13, 2019 · 1 comment
Closed

remove index column in SeriesGroupBy.nlargest #27894

RainFung opened this issue Aug 13, 2019 · 1 comment

Comments

@RainFung
Copy link

RainFung commented Aug 13, 2019

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

@TomAugspurger
Copy link
Contributor

I don't think we'll change this. It can be useful, matches the Series.nlargest behavior, and changing it would be API breaking.

If you don't need it then you can drop that level of the index afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants