Untitled
import pandas as pd def add_rolling_mean(df): # calculate the 20-day rolling mean for each stock symbol rolling_mean = df.groupby(level=0)['sentiment score'].rolling(window='20D').mean() # create a new column "20d_avg_score" with the rolling mean values df['20d_avg_score'] = rolling_mean.reset_index(level=0, drop=True) return df