Count items greater than a value in pandas groupby

You can try to do :

reviews[reviews['stars'] > 3].groupby('business_id')['stars'].count()

As I also wanted to rename the column and to run multiple functions on the same column, I came up with the following solution:

# Counting both over and under
reviews.groupby('business_id')\
       .agg(over=pandas.NamedAgg(column='stars', aggfunc=lambda x: (x > 3).sum()), 
            under=pandas.NamedAgg(column='stars', aggfunc=lambda x: (x < 3).sum()))\
       .reset_index()

The pandas.NamedAgg allows you to create multiple new columns now that the functionality was removed in newer versions of pandas.