2017-01-23 78 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

由于雅虎财务不保存历史商品价格,您会收到错误消息。