Skip to content

NamedAgg with as_index= False drops aggregated values #32240

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
RaghavaDhanya opened this issue Feb 25, 2020 · 0 comments · Fixed by #33247
Closed

NamedAgg with as_index= False drops aggregated values #32240

RaghavaDhanya opened this issue Feb 25, 2020 · 0 comments · Fixed by #33247
Labels
Bug Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@RaghavaDhanya
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd

file_name = "https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv"
df = pd.read_csv(file_name)

df[['species','petal_width']].groupby('species', as_index=False).agg(min_width=pd.NamedAgg(column='petal_width', aggfunc='min'))

Problem description

When I try to use as_index=Falsewith named aggregations it seems to be dropping values and replacing them with index. This is the output of the above code.

min_width
0 setosa
1 versicolor
2 virginica

Expected Output

species min_width
0 setosa 0.1
1 versicolor 1
2 virginica 1.4

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.3.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.14.138+
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : en_US.UTF-8
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.0.1
numpy            : 1.16.4
pytz             : 2019.1
dateutil         : 2.8.0
pip              : 19.1
setuptools       : 41.0.1
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.10.1
IPython          : 7.5.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : 3.1.1
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
pytest           : None
pyxlsb           : None
s3fs             : None
scipy            : 1.3.0
sqlalchemy       : 1.3.4
tables           : None
tabulate         : None
xarray           : 0.12.2
xlrd             : None
xlwt             : None
xlsxwriter       : None
numba            : None
@jreback jreback added Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode Bug labels Apr 19, 2020
@jreback jreback added this to the 1.1 milestone Apr 19, 2020
@jreback jreback modified the milestones: 1.1, Contributions Welcome Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants