Visit complete course on Data Science with Python :
https://www.udemy.com/data-science-with-python-and-pandas/?couponCode=YTSOCIAL090
For All other visit my udemy profile at :
https://www.udemy.com/user/ankitmistry/
This video will explain how to calculate moving average of time series data with python pandas library rolling function.
# # Calculate Moving average of Time series data
# # 1, 4, 7, 9, 2, 4, 6, 7, 8
# ## (NAN+1)/2 (1+4)/2 (4+7)/2 (7+9)/2 (9+2)/2
# In[4]:
import pandas as pd
# In[7]:
data1 = {'data':[1, 4, 7, 9, 2, 4, 6, 7, 8]}
# In[8]:
data1
# In[9]:
df = pd.DataFrame(data1)
# In[10]:
df
# In[12]:
df1 = df.rolling(3).mean()
df1
# In[13]:
import matplotlib.pyplot as plt
# In[14]:
plt.plot(df['data'])
plt.plot(df1['data'])
plt.show()