推荐一个网站:tushare
使用方法如下:
pip install tushare
我是使用pycharm直接安装的
抓取了浦发和光大的股票数据,并通过csv进行保存,和通过plt进行图片打印
import numpy as np import matplotlib.pyplot as plt import pandas as pd import tushare as ts s_pf = '600000' s_gd = '601818' sdata = '2016-12-08' edata = '2017-12-08' df_pf = ts.get_h_data(s_pf,start=sdata,end=edata).sort_index(axis=0,ascending=True) df_gd = ts.get_h_data(s_gd,start=sdata,end=edata).sort_index(axis=0,ascending=True) df = pd.concat([df_pf.close,df_gd.close],axis=1,keys=['pl_close','gd_close']) df.ffill(axis=0,inplace=True) df.to_csv('pf_gd.csv') #df = pd.read_csv('pf_gd.csv') corr = df.corr(method = 'pearson',min_periods=1) print(corr) df.plot(figsize = (20,12)) plt.savefig('pf_gd.pdf') plt.close()