获取tushare日线数据
示例
pro = ts.pro_api()df = pro.daily(ts_code='000001.SZ', start_date='20180701', end_date='20180718')#多个股票
df = pro.daily(ts_code='000001.SZ,600000.SH', start_date='20180701', end_date='20180718')
或者
df = pro.query('daily', ts_code='000001.SZ', start_date='20180701', end_date='20180718')
df = pro.daily(trade_date='20180810')
数据样例
ts_code trade_date open high low close pre_close change pct_chg vol amount
0 000001.SZ 20180718 8.75 8.85 8.69 8.70 8.72 -0.02 -0.23 525152.77 460697.377
1 000001.SZ 20180717 8.74 8.75 8.66 8.72 8.73 -0.01 -0.11 375356.33 326396.994
2 000001.SZ 20180716 8.85 8.90 8.69 8.73 8.88 -0.15 -1.69 689845.58 603427.713
3 000001.SZ 20180713 8.92 8.94 8.82 8.88 8.88 0.00 0.00 603378.21 535401.175
4 000001.SZ 20180712 8.60 8.97 8.58 8.88 8.64 0.24 2.78 1140492.31 1008658.828
5 000001.SZ 20180711 8.76 8.83 8.68 8.78 8.98 -0.20 -2.23 851296.70 744765.824
6 000001.SZ 20180710 9.02 9.02 8.89 8.98 9.03 -0.05 -0.55 896862.02 803038.965
7 000001.SZ 20180709 8.69 9.03 8.68 9.03 8.66 0.37 4.27 1409954.60 1255007.609
8 000001.SZ 20180706 8.61 8.78 8.45 8.66 8.60 0.06 0.70 988282.69 852071.526
9 000001.SZ 20180705 8.62 8.73 8.55 8.60 8.61 -0.01 -0.12 835768.77
CREATE TABLE `stock_daily` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ts_code` varchar(12) DEFAULT '',
`trade_date` varchar(10) DEFAULT '',
`open` decimal(10,2) DEFAULT '0.00',
`high` decimal(10,2) DEFAULT '0.00',
`low` decimal(10,2) DEFAULT '0.00',
`close` decimal(10,2) DEFAULT '0.00',
`pre_close` decimal(10,2) DEFAULT '0.00',
`change` decimal(10,2) DEFAULT '0.00',
`pct_chg` decimal(10,2) DEFAULT '0.00',
`vol` decimal(10,2) DEFAULT '0.00',
`amount` decimal(10,2) DEFAULT '0.00',
PRIMARY KEY (`id`),
UNIQUE KEY `uni_key` (`trade_date`,`ts_code`) USING BTREE,
KEY `ts_code` (`ts_code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
pymysql数据库操作错误
SQL上传时错误。错误描述TypeError: not all arguments converted during string formatting:
query = "INSERT INTO stock_basic (id,ts_code,trade_date,open,high,low,close,pre_close,change,pct_chg,vol,amount) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);" insert语句少了一个%s
python向mysql插入数据一直报TypeError: must be real number,not str
Python向MySQL中写入数据时无论输入的数据类型如何,语句中的占位符均使用%s,所以尽管price是float类型,但是占位符不能使用%f,还是要使用%s
也就是无论输入的数据是否为字符串,占位符都是%s,不存在%f,%d这种概念!!!!