Can't use same function twice with named aggregation · Issue #28426 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd from functools import partial

quant50 = partial(np.percentile, q=50) quant70 = partial(np.percentile, q=70)

test = pd.DataFrame({'col1': ['a', 'a', 'b', 'b', 'b'], 'col2': [1,2,3,4,5]})

test.groupby('col1').agg( quantile_50=('col2', quant50), quantile_70=('col2', quant70) )

Problem description

I'm trying to calculate multiple percentiles, I get the following error: "Function names must be unique, found multiple named percentile"

It's an old problem #7186 but I assumed that it should've been solved with the named aggregations. Now there is no need to deduce the column name from the function name, the column name was specified explicitly.

Expected Output

column | quantile_50 | quantile_70
a | 1.5 | 2
b | 4.0 | 3

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.1.11-200.fc29.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.1
numpy : 1.16.4
pytz : 2017.3
dateutil : 2.7.2
pip : 19.1.1
setuptools : 39.1.0
Cython : 0.28.1
pytest : 3.3.1
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.0
xlsxwriter : None
lxml.etree : 4.3.3
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 6.3.1
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.3.3
matplotlib : 2.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.9.0
pytables : None
s3fs : None
scipy : 1.2.1
sqlalchemy : 1.1.18
tables : None
xarray : None
xlrd : 1.1.0
xlwt : None
xlsxwriter : None