-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
NamedAgg error: aggregate() missing 1 required positional argument: 'func' #32803
Comments
Can you try to provide a small reproducible example with the error message you're seeing (others don't have access to your data)? |
I got the same error with resampling and aggregating. However, if you switch order with aggregation and then resampling it works but the result is datetime object which is not aggregated within dates. def new_dataset(rule,num_points = 9):
'''
Generate a new timeseries dataset using intervals in rule string
and number of points num_points
Returns a series object
'''
ind = pd.date_range('1/1/2000', periods=num_points, freq=rule)
return pd.Series(list(map(lambda x: x*2,range(num_points))), index=ind)
minutes = new_dataset('min')
minutes.resample('2min',axis=0).agg(column1 = ('mean', 'mean'), column2 = ('sum', 'sum')) The above results in
However, with
Call is made twice to only first aggregation which is supported even if call Credits: https://towardsdatascience.com/using-the-pandas-resample-function-a231144194c4 |
@brylie ideally the code sample could double as the test, so a minimal reproducible example would be beneficial, see https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports |
Pretty sure this is the same as the issue I opened here, so I'll copy over the example I put there: import pandas as pd
df = pd.DataFrame(
{"group": ["a"], "col": [1.0]}, index=[pd.to_datetime("2019-11-04 10:32:09.737")]
)
df.groupby("group").resample("1D").agg(open=pd.NamedAgg("col", "first")) all will close that one |
you can see the comment in pandas.core.base.SelectionMixin._aggregate, line 320&331
or use multiple group func
or give clear indication of func param
|
Code Sample, a copy-pastable example if possible
Problem description
This error prevents me from aggregating data and (re)naming columns at the same time. Instead, it is necessary to use the following approach, which isn't altogether bad:
Expected Output
The aggregate function would produce a new DataFrame with the following columns:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-19-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 18.1
setuptools : 40.8.0
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.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: