import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
nt=pd.read_excel('C:\\Users\MECHREVO\Desktop\TRD_Nrrate.xlsx') #导入外部数据
nt=nt.array(nt)
nt1=nt.iloc[2:]#切片操作
nt1['Clsdt']=nt1['Clsdt'].astype('str')
nt1.index=pd.to_datetime(nt1['Clsdt'])#时间格式转换
from pylab import mpl
nt1.head()
mpl.rcParams['font.sans-serif']=['SimHei']#确保显示中文
mpl.rcParams['axes.unicode_minus']=False #确保显示负数
#画时间序列图
nt1['国债收益率']=nt1.Nrradydt
nt1_1=nt1[['国债收益率']>0]#条件性提取收益率大于0的天数
nt1_2=nt1['国债收益率'].rolling(window=30).mean()
nt1=nt1.iloc[1:]
plt.figure(figsize=(9,6))
plt.plot(nt1.index,nt1['国债收益率'],'r-',label='国债收益率',lw=20)
plt.xlabel(u'日期',fontsize=14)
plt.ylabel(u'利率',fontsize=14,rotation=0)
plt.legend(loc=0,fontsize=14)
plt.grid()