2017-01-23 76 views
0

我正在使用雅虎財務閱讀股票數據到python。它適用於股票,但是它會給商品帶來錯誤。將商品閱讀爲與雅虎金融的蟒蛇

下面的代碼工作完美:

import pandas as pd 
import numpy as np 
import pandas.io.data as web 
import datetime 

# We will look at stock prices over the past year, starting at January 1, 2016 
start = datetime.datetime(2016,1,1) 
end = datetime.date.today() 

stock = "AAPL" 

# get stock data, from yahoo finance within the dates specified 
stock = web.DataReader(stock, "yahoo", start, end) 

stock.head(n=3) 

但是,如果你改變了手柄商品而不是股票,你得到這個錯誤:

import pandas as pd 
import numpy as np 
import pandas.io.data as web 
import datetime 

# We will look at stock prices over the past year, starting at January 1, 2016 
start = datetime.datetime(2016,1,1) 
end = datetime.date.today() 

stock = "GCG17.CMX" 

# get stock data, from yahoo finance within the dates specified 
stock = web.DataReader(stock, "yahoo", start, end) 

stock.head(n=3) 

OSError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.finance.yahoo.com/table.csv?s=GCG17.CMX&a=0&b=1&c=1970&d=0&e=22&f=2017&g=d&ignore=.csv' 

誰能幫助我?

+2

將此輸入到瀏覽器中,然後您將看到爲什麼http://ichart.finance.yahoo.com/table.csv?s=GCG17.CMX&a=0&b=1&c=1970&d=0&e=22&f=2017&g=d&ignore=的.csv – e4c5

回答

0

您可以使用YQL Console並嘗試使用SQL來提取所需的數據。

例如,我嘗試select * from yahoo.finance.historicaldata where symbol = "AAPL" and startDate = "2016-01-01" and endDate = "2017-01-22併成功獲取我想要的表格。

如果我將「AAPL」替換爲「GCG17.CMX」,我什麼都得不到。因此,我不認爲Python中的庫如熊貓和yahoo_finance有任何問題。問題發生在雅虎方面。

您可能會嘗試查找其他數據庫,如沃頓數據服務等,以獲取您想要的表格。希望這可以幫助。

0

由於雅虎財務不保存歷史商品價格,您會收到錯誤消息。