pandas rolling mean (also known as the moving average). 1

pandas rolling mean (also known as the moving average).

#pandas.Series.rolling().mean() method

values = pd.DataFrame()
values['daily_values'] = pd.Series(range(1,20,2))
values

values['rolling_mean_2'] = values['daily_values'].rolling(2).mean()
values

Here is what the above code is Doing:
1. Create a dataframe with a column of daily values
2. Create a new column in the dataframe called rolling_mean_2
3. Use the .rolling() method to calculate the rolling mean of the daily values
4. The .rolling() method takes a window size as an argument. In this case, the window size is 2.
5. The .mean() method is then applied to the rolling window.

Similar Posts