我正在从雅虎下载标准普尔 500 指数的股票价格,该指数的交易量对于 32 位整数来说太大了。
def yahoo_prices(ticker, start_date=None, end_date=None, data='d'):
csv = yahoo_historical_data(ticker, start_date, end_date, data)
d = [('date', np.datetime64),
('open', np.float64),
('high', np.float64),
('low', np.float64),
('close', np.float64),
('volume', np.int64),
('adj_close', np.float64)]
return np.recfromcsv(csv, dtype=d)
这是错误:
>>> sp500 = yahoo_prices('^GSPC')
Traceback (most recent call last):
File "<stdin>", line 108, in <module>
File "<stdin>", line 74, in yahoo_prices
File "/usr/local/lib/python2.6/dist-packages/numpy/lib/npyio.py", line 1812, in recfromcsv
output = genfromtxt(fname, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/numpy/lib/npyio.py", line 1646, in genfromtxt
output = np.array(data, dtype=ddtype)
OverflowError: long int too large to convert to int
如果我将 dtype 声明为使用 int64,为什么我仍然会收到此错误?这是否表明 io 函数并没有真正使用我的 dtype 序列d
?
===编辑...添加示例 csv===
Date,Open,High,Low,Close,Volume,Adj Close
2012-06-15,1329.19,1343.32,1329.19,1342.84,4401570000,1342.84
2012-06-14,1314.88,1333.68,1314.14,1329.10,3687720000,1329.10
2012-06-13,1324.02,1327.28,1310.51,1314.88,3506510000,1314.88