# hanbb # come on!!! import tushare as ts import matplotlib.pyplot as plt # 股票数据获取 data = ts.get_hist_data('000001',start='2015-06-23',end='2017-11-16') # 收益率计算 data['returns'] = (data['close']-data['close'].shift(1))/data['close'].shift(1) returns = data["returns"].values returns_list = returns.tolist() # 将array 转化为lsit returns_list = returns_list[1:] # 舍去空值 # 绘制直方图 plt.hist(returns_list) plt.show()