-
-
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
BUG: agg function failed [how->mean,dtype->object] #57031
Comments
I am too keep getting the same error while using this line ----> products.groupby(["Brand"]).mean() |
This behavior was changed in pandas 2.0: https://pandas.pydata.org/docs/whatsnew/v1.5.0.html#numeric-only-default-value Specify |
Use this it will work fine Assuming 'df' is your DataFrame and 'grouping_columns' are the columns you're grouping byresult = df.groupby(grouping_columns).mean(numeric_only=True) |
what if you're using .agg() function to perform multiple operations on the grouped columns. eg : movies.groupby(['Director', 'Star1']).agg(['min', 'max', 'mean']) It shows the same error (TypeError: agg function failed [how->mean,dtype->object]) Even after I used the numeric_only = True parameter, it returned TypeError: Cannot use numeric_only=True with SeriesGroupBy.min and non-numeric dtypes. Please help |
you are trying to use the min() method on a data group that contains non-numeric (atypical) data types df.select_types(include='number') the .select_types(include='number') method selects only numeric columns from the Data Frame df |
not working for me. |
@sarwesh123 This works like magic. Thank you so much |
I"m using pandas version 2.2.2 still its not working |
used this : this feature is changed and readily available in documentation :) |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The .groupby is not excluding the strings(objects) in this dataframe. In the older versions (1.3.5 pandas), this works for mean, min, max and even aggregate function.
Expected Behavior
agg function failed [how->mean,dtype->object]
Installed Versions
INSTALLED VERSIONS
commit : f538741
python : 3.12.1.final.0
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 2.2.0
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.3.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.0.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.19.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 14.0.2
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: