从雅虎财经python一次下载多只股票 [英] Downloading mutliple stocks at once from yahoo finance python

查看:136
本文介绍了从雅虎财经python一次下载多只股票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于使用熊猫数据阅读器的雅虎财经的功能的问题.我已经使用了几个月的股票行情列表并在以下几行中执行它:

I have a question about the function of yahoo finance using the pandas data reader. I'm using for months now a list with stock tickers and execute it in the following lines:

import pandas_datareader as pdr
import datetime

stocks = ["stock1","stock2",....]
start = datetime.datetime(2012,5,31)
end = datetime.datetime(2018,3,1)

f = pdr.DataReader(stocks, 'yahoo',start,end)

从昨天开始,我收到错误IndexError: list index out of range",只有当我尝试获取多只股票时才会出现.

Since yesterday i get the error "IndexError: list index out of range", which appears only if I try to get multiple stocks.

最近几天有什么变化需要我考虑,或者您有更好的解决方案吗?

Has anything changed in recent days which I have to consider or do you have a better solution for my problem?

推荐答案

更新于 2021-01-19

  • 此时,OP 中的实现可以正常工作,可以下载多只股票.
  • 版本:0.9.0 日期:2020 年 7 月 10 日
  • GitHub:pydata/pandas-datareader
  • tickers = ['msft', 'aapl', 'twtr', 'intc', 'tsm', 'goog', 'amzn', 'fb', 'nvda']
    df = pdr.DataReader(tickers, data_source='yahoo', start='2017-01-01', end='2020-09-28')
    

    原答案

    如果您通读 Pandas DataReader 的 文档,他们发布了多个数据源 API 的立即折旧,其中之一是 Yahoo!金融.

    Original Answer

    If you read through Pandas DataReader's documentation, they issued an immediate depreciation on multiple data source API's, one of which is Yahoo! Finance.

    v0.6.0(2018 年 1 月 24 日)

    立即弃用 Yahoo!Google OptionsQuotesEDGAR.这些 API 背后的端点发生了根本性的变化,现有读者需要完全重写.对于大多数Yahoo!已删除端点的数据.PDR 想恢复这些欢迎使用功能和拉取请求.

    Immediate deprecation of Yahoo!, Google Options and Quotes and EDGAR. The end points behind these APIs have radically changed and the existing readers require complete rewrites. In the case of most Yahoo! data the endpoints have been removed. PDR would like to restore these features, and pull requests are welcome.

    这可能是导致您收到 IndexError(或任何其他通常不存在的错误)的罪魁祸首.

    This could be the culprit to why you been getting IndexError's (or any other normally none-existant errors).

    然而,还有另一个 Python 包的目标是修复对 Yahoo! 的支持.Pandas DataReader 财务,您可以在此处找到该软件包:

    However, there is another Python package whose goal is to fix the support for Yahoo! Finance for Pandas DataReader, you can find that package here:

    https://pypi.python.org/pypi/fix-yahoo-finance

    根据他们的文档:

    雅虎!Finance 已停用其历史数据 API,导致许多依赖它的程序停止工作.

    Yahoo! finance has decommissioned their historical data API, causing many programs that relied on it to stop working.

    fix-yahoo-finance 通过从 Yahoo!使用和返回 Pandas 融资pandas_datareader 格式相同的 DataFrame/Panelget_data_yahoo().

    fix-yahoo-finance offers a temporary fix to the problem by scraping the data from Yahoo! finance using and return a Pandas DataFrame/Panel in the same format as pandas_datareader’s get_data_yahoo().

    基本上是劫持"pandas_datareader.data.get_data_yahoo()方法,fix-yahoo-finance的植入很简单,只需要将 fix_yahoo_finance 导入您的代码.

    By basically "hijacking" pandas_datareader.data.get_data_yahoo() method, fix-yahoo-finance’s implantation is easy and only requires to import fix_yahoo_finance into your code.

    您需要添加的是:

    from pandas_datareader import data as pdr
    import fix_yahoo_finance as yf
    
    yf.pdr_override() 
    
    stocks = ["stock1","stock2", ...]
    start = datetime.datetime(2012,5,31)
    end = datetime.datetime(2018,3,1)
    
    f = pdr.get_data_yahoo(stocks, start=start, end=end)
    

    甚至不需要 Pandas DataReader:

    Or even without the need of Pandas DataReader:

    import fix_yahoo_finance as yf
    
    stocks = ["stock1","stock2", ...]
    start = datetime.datetime(2012,5,31)
    end = datetime.datetime(2018,3,1)
    data = yf.download(stocks, start=start, end=end)
    

    这篇关于从雅虎财经python一次下载多只股票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆