There is a dataframe of Pandas: id movie rating 0 Pulp Fiction (1994) 5.0 1 Three Colors: Red (1994) 3.5 2 Three Colors: Blue (1993) 5.0 3 Underground (1995) 5.0 4 Singing in the Rain (1952) 3.5 Write a function that creates a new 'class' column and substitutes values there depending on the rating: - grade 2 and below - low rating; - grade 4 and below - average rating; - 4.5 and 5 - high rating.
def ratings(x): if x <= 2.0: return 'Low' elif x <= 4.0: return 'Average' else: return 'High' df['rating'] = df['rating'].apply(ratings) df.head()