使用聚宽,登录并获取数据,将数据存入数据库,这是后续分析的基础。python
from jqdatasdk import * # 一、登录聚宽 auth('用户名','密码') # 二、获取数据生成dataframe格式的数据 df = get_price('000001.XSHE', start_date='2018-01-01', end_date='2018-09-01', frequency='daily', fields=['open', 'close', 'high', 'low']) # 三、将df写入price.csv文件 f = 'price.csv' df.to_csv(f) # 四、将df写入mysql数据库 from sqlalchemy import create_engine engine = create_engine('mysql+pymysql://root:password@localhost:3306/db01?charset=utf8') df.to_sql('normal', engine, schema='db01', if_exists='replace', index=True, index_label='date')