-2

I have to filter dark chocolate with yes and find mean of no of chocolate which is filtered after applying filter of "yes". Data Frame filtered and now i want to get mean(average) of filtered data. but when i use mean function it gives average of all data without filtering. name dark chocolate no of chocolate a yes 10 b no 5 c yes 20

  • 1
    Please provide sample data and the desired result. Read and apply [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – timgeb May 24 '20 at 19:00

1 Answers1

0

I think after filtering all the 'yes' values, you didn't save your dataframe to a new value. I think you tried calculating the mean something like this:

import pandas as pd df = pandas.DataFrame({'a': ['yes', 'no', 'yes' ], 'b': [10, 5, 20]}) df[df.a == 'yes'] df.b.mean()

Please write your second line this way:

df = df[df.a == 'yes'] df.b.mean()

It should work fine!

PRIN
  • 344
  • 1
  • 7