代码
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
aa =r'../data/000001.xlsx'
pd.set_option('display.max_columns',500)
pd.set_option('display.width',1000)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
df = pd.DataFrame(pd.read_excel(aa))
df['date'] = pd.to_datetime(df['date'])
df = df.set_index('date')
print(df)
df=df[['close']]
df['20天'] = np.round(df['close'].rolling(window = 20, center = False).mean(), 2)
df['50天'] = np.round(df['close'].rolling(window = 50, center = False).mean(), 2)
df['200天'] = np.round(df['close'].rolling(window = 200, center = False).mean(), 2)
plt.rcParams['font.sans-serif']=['SimHei']
df.plot(secondary_y = ["收盘价", "20","50","200"], grid = True)
plt.legend(('收盘价','20天', '50天', '200天'), loc='upper right')
plt.show()
效果

