You are given a DataFrame df with two columns: date (a datetime column, one row per day, but with some days absent and the rows not necessarily in order) and value (a float). A naive rolling(window) over the rows would treat the row before a gap as yesterday, so a 7-row window could span three weeks.
Implement solution(df, window) that returns a DataFrame with the columns date, value, rolling_mean and a fresh integer index:
df, in ascending order;value as given, and NaN on the days that were missing;rolling_mean as the mean of the available values over the trailing window of window calendar days ending on that day (the day itself included), ignoring missing days; a day with no available value in its window gets NaN.Rounding is not required. The input is never empty and has no duplicate dates.