Apply multiple functions to multiple groupby columns

The docs show how to apply multiple functions on a groupby object at a time using a dict with the output column names as the keys: In [563]: grouped[‘D’].agg({‘result1’ : np.sum, …..: ‘result2’ : np.mean}) …..: Out[563]: result2 result1 A bar -0.579846 -1.739537 foo -0.280588 -1.402938 However, this only works on a Series groupby object. … Read more

must appear in the GROUP BY clause or be used in an aggregate function

I have a table that looks like this caller ‘makerar’ cname | wmname | avg ——–+————-+———————— canada | zoro | 2.0000000000000000 spain | luffy | 1.00000000000000000000 spain | usopp | 5.0000000000000000 And I want to select the maximum avg for each cname. SELECT cname, wmname, MAX(avg) FROM makerar GROUP BY cname; but I will get … Read more

Get statistics for each group (such as count, mean, etc) using pandas GroupBy?

I have a data frame df and I use several columns from it to groupby: df[‘col1′,’col2′,’col3′,’col4’].groupby([‘col1′,’col2’]).mean() In the above way I almost get the table (data frame) that I need. What is missing is an additional column that contains number of rows in each group. In other words, I have mean but I also would … Read more