Pandas - Avoid boolean result when using groupby() I have this script:
    sectors = df.groupby(['company_sector']).mean()['investment_in_millions']

Output:

I wanted to keep the same groupy() but having a result in &quot;investment_in_millions&quot; column filtered as mean &gt; 10 or another value.
If apply this:
     sectors = df.groupby(['company_sector']).mean()['investment_in_millions']&gt;10

I keep the groupby() but it returns a boolean into the investment column.
If I use:
     filtered = df[df['investment_in_millions']&gt;10]

I get the filtered values mean&gt;10 but the groupby() is not there anymore and I get all the other columns in the excel.
How can I get the groupby() together with the mean&gt;10 without getting a boolean result?
Thanks!
First filter your results:
filtered_df = df[df['investment_in_millions']&gt;10]

And then group it by company_sector
import numpy as np 

sectors = filtered_df.groupby(['company_sector']).agg({&quot;investment_in_millions&quot;:np.mean})

You can do it in one line:
sectors = df[df['investment_in_millions']&gt;10].groupby(['company_sector']).agg({&quot;investment_in_millions&quot;:np.mean})