Forecasting models need features from the past, such as yesterday's sales and last week's average, computed separately for each store and without peeking at the future.
Given a DataFrame with columns store, date and sales (in any order), implement add_lag_features(df) that returns a new DataFrame:
store, then date, with a fresh index;lag_1: the store's sales on its previous row;rolling_mean_3: the mean of the store's previous 3 rows (not including the current one), requiring all 3 to exist;NaN. Don't modify the input DataFrame.