'Problem generating a list with a numeric qualifier

I am working on a course with low code requirements, and have one step where I am stuck.

I have this code that creates a list of restaurants and the number of reviews each has:

Filter the rated restaurants

df_rated = df[df['rating'] != 'Not given'].copy()

df_rated['rating'] = df_rated['rating'].astype('int')  
df_rating_count = df_rated.groupby(['restaurant_name'])['rating'].count().sort_values(ascending = False).reset_index()
df_rating_count.head() 

From there I am supposed to create a list limited to those above 50 reviews, starting from this base:

# Get the restaurant names that have rating count more than 50
rest_names = df_rating_count['______________']['restaurant_name'] 


# Filter to get the data of restaurants that have rating count more than 50
df_mean_4 = df_rated[df_rated['restaurant_name'].isin(rest_names)].copy()

# Group the restaurant names with their ratings and find the mean rating of each restaurant
df_mean_4.groupby(['_______'])['_______'].mean().sort_values(ascending = False).reset_index().dropna() ## Complete the code to find the mean rating

Where I am stuck is on the first step.

rest_names = df_rating_count['______________']['restaurant_name']

I am pretty confident in the other 2 steps.

df_mean_4 = df_rated[df_rated['restaurant_name'].isin(rest_names)].copy()
df_mean_4.groupby(['restaurant_name'])['rating'].mean().sort_values(ascending = False).reset_index().dropna()

I have frankly tried so many different things I don't even know where to start.

Does anyone have any hints to at least point me in the right direction?



Solution 1:[1]

you can index and filter using [].

# Get the restaurant names that have rating count more than 50
rest_names = df_rating_count[df_rating_count['rating'] > 50]['restaurant_name'] 

Solution 2:[2]

#function to determine the revenue
def compute_rev(x):
    if x > 20:
        return x*0.25
    elif x > 5:
        return x*0.15
    else:
        return x*0

## Write the appropriate column name to compute the revenue
df['Revenue'] = df['________'].apply(compute_rev)
df.head()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 greco
Solution 2 greybeard