def moving_average(data, target_var, features_list, num_days = 7):
    """
    Cacluate moving average of target variable and store result in a new column

    Parameters
    ----------
    data: data frame 
        It has columns location, date, and a column with the response variable to forecast.
        This data frame needs to be sorted by location and date columns in ascending order.
    target_var: string
        Name of the column in the data frame with the forecast target variable.
    features_list: list of strings
        Running list of feature column names
    num_days: integer
        Time window to calculate moving average for
    
    Returns
    -------
    data: data frame 
        Original data frame with additional column for moving average
    features_list: list of strings
        Running list of feature column names
    """
    column_name = str(num_days)+"_moving_avg_"+str(target_var)
    features_list.append(column_name)
    data[column_name] = data.groupby('location').rolling(num_days)[target_var].mean().reset_index(drop=True)
    return data, features_list