我正在编写以下代码行
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
tickers=['RELIANCE.NS','MBECL.NS']
mystocks=pd.DataFrame()
for t in tickers:
mystocks[t]=wb.DataReader(t,data_source='yahoo',start='2015-1-1')['Adj Close']
mystocks
但这返回了
ConnectionError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Read timed out.
从浏览器访问Yahoo Finance。直到上周我才能够执行此操作,但是现在同一行代码抛出连接错误。
答案 0 :(得分:2)
我建议您将获取数据帧的代码放在 try / except 语句中。这样它就会等到你的连接重新建立。
for t in tickers:
try:
mystocks[t]=wb.DataReader(t,data_source='yahoo',start='2015-1-1')['Adj Close']
except:
continue
mystocks