# Create a new DataFrame that includes only the title_name and genres columns, and remove the square brackets and spaces from the genres column
df = dim_titles_roku_python[['title_name', 'genres']].copy() # make a copy to avoid modifying the original DataFrame
df.loc[:, 'genres'] = df['genres'].str.replace('[', '', regex=True).str.replace(']', '', regex=True).str.replace(' ', '', regex=True)
# df['genres'] = df['genres'].str.replace('[', '').str.replace(']', '').str.replace(' ', '')
# Use the `apply` function to split the genres column into a list of individual genres
df = df.apply(
lambda x: pd.Series(x['genres'].split(',')),
axis=1).stack().reset_index(level=1, drop=True)
# Use the `reset_index` function to create a new DataFrame where each genre is a separate row
df = df.reset_index(name='genre')
# Use the `groupby` and `size` functions to count the number of occurrences of each genre
df = df.groupby('genre').size().reset_index(name='frequency')
# Sort the resulting DataFrame by the frequency column in descending order
df = df.sort_values(by='frequency', ascending=False).head(10)
print(df)