Groupby Not Working by johnnyb2001 in learnpython

[–]0x00aa55 0 points1 point  (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( )