Skip to content
Advertisement

Groupby mean doesn’t display all data

I want to see all the means of the numerical columns, grouped by position, using

dfMockPos.groupby(['Position']).mean()

When I do this I only get 3 of the many columns

enter image description here

The other columns are all integers or floats, and they have no NAs.

If I do

dfMockPos['Weight'].mean()

Then I get the correct output. How can I display weight using groupby?

Thanks for any help

Advertisement

Answer

You can try using the Aggregate function on groupby.

For example:

dfMockPos.groupby(['Position']).agg({"relative_age":'mean',
                                             "Height": 'mean',
                                             "Success_score": "mean",
                                             "Weight": "mean" })
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement