" get_data_yahoo"来自" pandas_datareader"返回空DataFrame

时间:2017-08-16 02:05:30

标签: python pandas yahoo-finance pandas-datareader

我试图使用" get_data_yahoo"来获取股票数据。方法来自" pandas_datareader"所以我写了以下内容来测试它。我了解到Yahoo API存在问题所以我按照here指令添加" fix_yahoo_finance"模块和from pandas_datareader import data as pdr import fix_yahoo_finance as yf from datetime import datetime yf.pdr_override() a = pdr.get_data_yahoo('AAPL', start=datetime(2017, 8, 13), end=datetime(2017, 8, 14)) b = pdr.get_data_yahoo('AMZN', start=datetime(2017, 8, 13), end=datetime(2017, 8, 14)) c = pdr.get_data_yahoo('MSFT', start=datetime(2017, 8, 13), end=datetime(2017, 8, 14)) print(a) print(b) print(c)

import Starscream    

class ViewController: UIViewController {

let conn = ConnectionManager()


override func viewDidLoad() {
    super.viewDidLoad()

    conn.startSession()
}

}


class ConnectionManager {

    let socket = WebSocket(url: URL(string: "ws://localhost:8080/")!)

    func startSession(){
        socket.delegate = self
        socket.connect()
    }
}

extension ConnectionManager: WebSocketDelegate{
    func websocketDidConnect(socket: WebSocket) {
        print("connected")
    }

    func websocketDidDisconnect(socket: WebSocket, error: NSError?) {

    }

    func websocketDidReceiveMessage(socket: WebSocket, text: String) {
        print("text")
    }

    func websocketDidReceiveData(socket: WebSocket, data: Data) {

    }

//put the delegate methods here

但是,当我运行上面的代码时,有时无法获取股票,导致一个或两个DataFrame(或全部三个)如下所示。 enter image description here enter image description here 在第一张图片中,仅获取第一张图片,而在第二张图片中仅获取第二张图片 我尝试了不同的代码并运行了很多次,这似乎是一个随机的模式。有谁知道发生了什么?这个模块是否再次被打破或者我可以修复的东西是什么?提前致谢。

1 个答案:

答案 0 :(得分:0)

我无法立即诊断此处发生的确切问题,但这是一种解决方法:

stock_list = ['AMZN', 'MSFT', 'AAPL']
stock_dict = {}
for stock in stock_list:
    dim = (0,0)
    while dim != (1,6):
       s = pdr.get_data_yahoo(stock, start="2017-08-13",end="2017-08-14")
       dim = s.shape
    stock_dict[stock] = s