# import necessary libraries
import pandas as pd

# define your series
my_series = pd.Series([8, 8, 1, 2, 1, 1, 7, 8, 9, 2])

# find frequency counts of elements
counts = my_series.value_counts()

# sort the values in descending order
counts = counts.sort_values(ascending = False)

# separate the first 2 frequent values and print them
top_two = counts.index[:2]
print(f'Top 2 Frequent Values: {top_two.values}')

# apply transform() using a simple lambda func
my_series = my_series.transform(lambda x: 'Other' \
                                if x not in top_two \
                                else x)

# print the series
print(f"Updated Series: \n{my_series}")