Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Finding the mean of 2 different values in a column

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’d use df.groupby.mean:

df.groupby(['color'])['items'].mean()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading