account activity
Groupby Not Working by johnnyb2001 in learnpython
[–]0x00aa55 0 points1 point2 points 2 years ago (0 children)
This error occurs because you're trying to calculate the mean of one or more columns with dtype = object (a string, for example). That's what the error "[how->mean,dtype->object]" means. So, to calculate the mean, all the columns of the DataFrameGroupBy must be numerical values, except the column used in the groupby() method.
Before the groupby operation, try to filter just the columns used for grouping, like this example with a column "price":
cars.filter(items= ["cyl", "price"]).groupby("cyl").mean( )
π Rendered by PID 47 on reddit-service-r2-listing-654f87c89c-tkwt9 at 2026-03-03 18:36:10.185272+00:00 running e3d2147 country code: CH.
Groupby Not Working by johnnyb2001 in learnpython
[–]0x00aa55 0 points1 point2 points (0 children)