量化策略多因子选股之抓取数据并保存到本机MYSQL数据库

数据来自于tushare

使用了sqlalchemy 包的引擎来保存数据与SQL


# coding=utf-8
import pandas as pd
import tushare as ts
import sys
from sqlalchemy import create_engine

reload(sys)
sys.setdefaultencoding("utf-8")


zz500=ts.get_zz500s()
hs300=ts.get_hs300s()

zz500_code= zz500['code']
hs300_code= hs300['code']

get_industry= ts.get_industry_classified()

print get_industry
# 得到sina行业分类
get_industry_hs300= get_industry[get_industry['code'].isin(hs300_code) ]
get_industry_zz500= get_industry[get_industry['code'].isin(zz500_code) ]


#得到2017年第四季度的主报数据
df1=get_report=ts.get_report_data(2017,4)


#得到2017年第四季度的盈利能力数据
df2=ts.get_profit_data(2017,4)


#得到2017年第四季度的成长能力数据
df3=ts.get_growth_data(2017,4)


engine = create_engine('mysql://root:********@127.0.0.1/stock_report?charset=utf8')

df1.to_sql('get_report',engine)
df2.to_sql('get_report2',engine)
df3.to_sql('get_report3',engine)

frames = [get_industry_hs300, get_industry_zz500]
result = pd.concat(frames)
result.to_sql('hangye',engine)

数据预览:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值