Moving Average Pandas

The rolling mean returns a Series you only have to add it as a new column of your DataFrame (MA) as described below. For information, the rolling_mean function has been deprecated in pandas newer versions. I have used the new method in my example, see below a quote from the pandas documentation. Warning Prior to version 0.18.0, pd.rolling_*, pd.expanding_*, and pd.ewm* were module level functions and are … Read more

Moving average or running mean

UPDATE: more efficient solutions have been proposed, uniform_filter1d from scipy being probably the best among the “standard” 3rd-party libraries, and some newer or specialized libraries are available too. You can use np.convolve for that: Explanation The running mean is a case of the mathematical operation of convolution. For the running mean, you slide a window along the input and compute the mean of … Read more