(1)mysql 32位
anaconda 32
tushare
cd tushare filefolder
python setup.py install
http://sourceforge.net/projects/mysql-python/
(2)
import tushare as ts
adata=ts.get_hist_data(‘600292’,ktype=’30’)
open high close low volume price_change date
2015-07-28 10:30:00 17.71 18.53 18.05 17.69 35385.40 0.34
2015-07-28 11:00:00 18.06 19.96 19.96 17.89 32036.20 1.90
2015-07-28 11:30:00 19.98 19.99 19.10 18.75 24075.10 -0.88
2015-07-28 13:30:00 19.10 19.10 18.26 18.20 17952.80 -0.84
2015-07-28 14:00:00 18.31 18.74 18.23 18.17 16491.10 -0.08
date不算数据,与tick 对比一下
type(adata)
Out[30]: pandas.core.frame.DataFrame
adata.dtypes
Out[33]:
open float64
high float64
close float64
low float64
volume float64
price_change float64
p_change float64
ma5 float64
ma10 float64
ma20 float64
adata[‘open’]
Out[40]:
date
2015-07-28 10:30:00 17.71
2015-07-28 11:00:00 18.06
2015-07-28 11:30:00 19.98
(3)
from sqlalchemy import create_engine
import tushare as ts
df = ts.get_tick_data(‘600848’, date=’2014-12-22’)
engine = create_engine(‘mysql://user:[email protected]/db_name?charset=utf8’)
df.to_sql(‘tick_data’,engine)
df.dtypes
Out[5]:
time object
price float64
change object
volume int64
amount int64
type object
dtype: object
df
time price change volume amount type
0 15:00:03 17.37 -0.01 44 76428 中性盘
1 14:59:58 17.38 – 850 1477300 买盘
2 14:59:53 17.38 0.01 104 180752 买盘
3 14:59:48 17.37 – 78 135486 卖盘
4 14:59:43 17.37 – 405 703485 买盘
5 14:59:38 17.37 – 82 142434 买盘
6 14:59:33 17.37 0.01 81 140697 买盘
adata.index
Out[7]:
Index([u’2015-07-28 10:30:00’, u’2015-07-28 11:00:00’, u’2015-07-28 11:30:00’,
u’2015-07-28 13:30:00’, u’2015-07-28 14:00:00’, u’2015-07-28 14:30:00’,
u’2015-07-28 15:00:00’, u’2015-07-29 10:00:00’, u’2015-07-29 10:30:00’,
u’2015-07-29 11:30:00’,
…
u’2015-10-08 14:30:00’, u’2015-10-08 15:00:00’, u’2015-10-09 10:00:00’,
u’2015-10-09 10:30:00’, u’2015-10-09 11:00:00’, u’2015-10-09 11:30:00’,
u’2015-10-09 13:30:00’, u’2015-10-09 14:00:00’, u’2015-10-09 14:30:00’,
u’2015-10-09 15:00:00’],
dtype=’object’, name=u’date’, length=350)
df.index
Out[8]:
Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
…
2286, 2287, 2288, 2289, 2290, 2291, 2292, 2293, 2294, 2295],
dtype=’int64’, length=2296)