Home > Mobile >  Finding the mean of 2 different values in a column
Finding the mean of 2 different values in a column

Time:12-12

I would like to find the mean of 2 different values in a column, but I am unsure how to do this. For example, if I had a dataframe, and there was a column named 'color' that was either red or blue, how would I find the mean of all the red items and all the blue items? I am only able to find the mean of the total number of items

Thank you

CodePudding user response:

You'd use df.groupby.mean:

df.groupby(['color'])['items'].mean()
  • Related