0
有問題索引一個numpy的陣列後,我從ystockquote導入股票報價:ystockquote數據導入numpy的陣列,IndexError:數組太多指數
import numpy as np
import ystockquote as ysq
startdate = "2016-04-06"
enddate = "2016-04-07"
q = np.array(ysq.get_historical_prices("AAPL", startdate, enddate))
print(q)
{'2016-04-07': {'Close': '108.540001', 'Volume': '30881000', 'Adj Close': '108.540001', 'High': '110.419998', 'Low': '108.120003', 'Open': '109.949997'}, '2016-04-06': {'Close': '110.959999', 'Volume': '26047800', 'Adj Close': '110.959999', 'High': '110.980003', 'Low': '109.199997', 'Open': '110.230003'}}
q[0,0]
Traceback (most recent call last):
File "<ipython-input-105-ad764cdee54e>", line 1, in <module>
q[0,0]
IndexError: too many indices for array
q[0,:]
Traceback (most recent call last):
File "<ipython-input-106-069fcfa0a0f6>", line 1, in <module>
q[0,:]
IndexError: too many indices for array
q[:,0]
Traceback (most recent call last):
File "<ipython-input-107-782637b90296>", line 1, in <module>
q[:,0]
IndexError: too many indices for array
q.shape
Out[108]:()
看來,數組有沒有尺寸。任何人都可以解釋發生了什麼?
謝謝Padraic。我對Python仍然很陌生。目標是將數據轉換爲一個numpy數組,每行表示一個日期的數據(即6個數據點)。 當我打電話給 print(q [0]) 時,我仍然得到索引錯誤,這可能是版本問題?我在Spyder 2.3.8中使用IPython(Python 3.5) – Thor
@Thor,啊,好吧,我們需要爲python 3調用'list(d.items())' –
現在工作 - thx! – Thor