Finding the mean of 2 different values in a column

Question:

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

Asked By: user20266015

||

Answers:

You’d use df.groupby.mean:

df.groupby(['color'])['items'].mean()
Answered By: Jab
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.