Answers for "moving mean average python"

5

rolling average df

df['pandas_SMA_3'] = df.iloc[:,1].rolling(window=3).mean()
Posted by: Guest on April-14-2020
0

12 month movinf average in python for dataframe

start_date = '2015-01-01'
end_date = '2016-12-31'

fig, ax = plt.subplots(figsize=(16,9))

ax.plot(data.loc[start_date:end_date, :].index, data.loc[start_date:end_date, 'MSFT'], label='Price')
ax.plot(long_rolling.loc[start_date:end_date, :].index, long_rolling.loc[start_date:end_date, 'MSFT'], label = '100-days SMA')
ax.plot(short_rolling.loc[start_date:end_date, :].index, short_rolling.loc[start_date:end_date, 'MSFT'], label = '20-days SMA')

ax.legend(loc='best')
ax.set_ylabel('Price in $')
ax.xaxis.set_major_formatter(my_year_month_fmt)
Posted by: Guest on December-27-2020

Python Answers by Framework

Browse Popular Code Answers by Language