python - 如何使用 pandas 和 yahoo finance 获得 ' USDJPY'(货币汇率)?

标签 python ios pandas currency yahoo-finance

我正在学习和使用 pandas 和 python。

今天,我正在尝试制作一个外汇汇率表, 但我在获取“USDJPY”的价格时遇到了麻烦。

当我得到“EUR/USD”的价格时,我会这样编码。

eur = web.DataReader('EURUSD=X','yahoo')['Adj Close']

有效。

但是当我写的时候

jpy = web.DataReader('USDJPY=X','yahoo')['Adj Close']

错误信息是这样的:

--------------------------------------------------------------------------- IOError Traceback (most recent call last) in () ----> 1 jpy = web.DataReader('USDJPY=X','yahoo')['Adj Close']

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in DataReader(name, data_source, start, end, retry_count, pause) 70 return get_data_yahoo(symbols=name, start=start, end=end, 71 adjust_price=False, chunksize=25, ---> 72 retry_count=retry_count, pause=pause) 73 elif data_source == "google": 74 return get_data_google(symbols=name, start=start, end=end,

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in get_data_yahoo(symbols, start, end, retry_count, pause, adjust_price, ret_index, chunksize, name) 388 """ 389 return _get_data_from(symbols, start, end, retry_count, pause, --> 390 adjust_price, ret_index, chunksize, 'yahoo', name) 391 392

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in _get_data_from(symbols, start, end, retry_count, pause, adjust_price, ret_index, chunksize, source, name) 334 # If a single symbol, (e.g., 'GOOG') 335 if isinstance(symbols, (basestring, int)): --> 336 hist_data = src_fn(symbols, start, end, retry_count, pause) 337 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT']) 338 elif isinstance(symbols, DataFrame):

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in _get_hist_yahoo(sym, start, end, retry_count, pause) 188 '&g=d' + 189 '&ignore=.csv') --> 190 return _retry_read_url(url, retry_count, pause, 'Yahoo!') 191 192

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in _retry_read_url(url, retry_count, pause, name) 167 168 raise IOError("after %d tries, %s did not " --> 169 "return a 200 for url %r" % (retry_count, name, url)) 170 171

IOError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.yahoo.com/table.csv?s=USDJPY=X&a=0&b=1&c=2010&d=1&e=1&f=2014&g=d&ignore=.csv'

'GBPUSD' 等其他货币也有同样的问题。

你能解决这个问题吗?

你有没有想过从雅虎或谷歌获取“USDJPY”???

最佳答案

Yahoo Finance 不提供汇率的历史数据(即页面左上角没有“历史价格”链接,就像股票、指数等...)

您可以使用 FRED(圣路易斯联邦储备银行数据)来获取这些汇率...

import pandas.io.data as web

jpy = web.DataReader('DEXJPUS', 'fred')

更新:hase 移动了 pandas-datareader

from pandas_datareader import data
jpy = data.DataReader('DEXJPUS', 'fred')

或者更直接的方式...

jpy = web.get_data_fred('DEXJPUS')

可在此处找到 FRED 每日数据的所有汇率列表:http://research.stlouisfed.org/fred2/categories/94

关于python - 如何使用 pandas 和 yahoo finance 获得 ' USDJPY'(货币汇率)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21483959/

相关文章:

python - python 导演使用的 swig 错误 c++

python - 在 Python 中找到一个数字范围内最小的可整除数,谜题

python - 将嵌套的字典列表转换为 pandas DataFrame

ios - Sqlite_prepare_v2返回SQLite_ERROR

html - 在 iOS 中抓取 HTML

python - 根据选定的窗口进行数据帧聚合

ios - 使用 UIPanGestureRecognizer 计算轻弹后 UIView 的最终位置

python - 从不同的 DataFrame 中减去值

python - 在 Pandas 中设置最大字符串长度

python - 如何在组内逐条查找唯一值?