使用聚寬,登錄並獲取數據,將數據存入數據庫,這是後續分析的基礎。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')