使用 web.DataReader 加载数据时出错,yahoo finance

Error when loading data using web.DataReader, yahoo finance

我尝试使用 web.DataReader 加载数据,但我总是收到错误“RemoteDataError:无法读取 URL:https://finance.yahoo.com/quote/FB/history?period1=1325390400&period2=1577937599&interval=1d&frequency=1d&filter=history"

我已经使用了以下软件包更新,昨天我的代码运行良好。但是今天我仍然遇到与以前相同的错误(即无法读取 URL)。

!pip install --upgrade pandas
!pip install --upgrade pandas-datareader

PS:我使用 Google Colab

这是我的代码的完整开头(包括错误):

!pib install numpy
!pib install matplotlib
!pib install pandas
!pip install --upgrade pandas
!pip install --upgrade pandas-datareader

 # Importing packages
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import pandas_datareader as web
import datetime as dt
from sklearn.preprocessing import MinMaxScaler #package used in order to scale the data
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, LSTM
# Load Data 
company = 'FB' #picking the company we want to study

start=dt.datetime(2012,1,1) # picking the dataframe we are interested in 
end=dt.datetime(2020,1,1)
data = web.DataReader(company, 'yahoo',start,end)

RemoteDataError Traceback(最后一次调用) 在 () ----> 1 条数据 = web.DataReader(公司,'yahoo',开始,结束)

4帧 /usr/local/lib/python3.7/dist-packages/pandas_datareader/base.py in _get_response(self, url, params, headers) 179 msg += "\n响应文本:\n{0}".format(last_response_text) 180 --> 181 引发 RemoteDataError(msg) 182 183 def _get_crumb(自身,*args):

RemoteDataError:无法读取 URL:https://finance.yahoo.com/quote/FB/history?period1=1325390400&period2=1577937599&interval=1d&frequency=1d&filter=history 响应文本: b'\n \n \n \n Yahoo\n \n \n \n html {\n 高度:100%;\n }\n 主体 {\n 背景:#fafafc url(https://s.yimg.com/nn/img/sad-panda-201402200631.png) 50% 50%;\n background-size: cover;\n height: 100%;\n text-align: center;\n font: 300 18px "helvetica neue", helvetica, verdana、tahoma、arial、sans-serif;\n }\n table {\n 高度:100%;\n 宽度:100%;\n table-布局:固定;\n 边框-collapse: collapse;\n border-spacing: 0;\n border: none;\n }\n h1 {\n font-size: 42px;\n font-weight: 400;\n color: #400090;\n }\n p {\n 颜色:#1A1A1A;\n }\n #message-1 {\n 字体粗细:粗体;\n 边距:0;\n }\n #message-2 { \n 显示:内联块;\n *显示:内联;\n 缩放:1;\n 最大宽度:17em;\n _width:17em;\n }\n \n \n document.write( '&test=\'+encodeURIComponent(\'%\')+\'" width="0px" height="0px"/>');var beacon = new Image();beacon.src="// bcn.fp.yahoo.com/p?s=1197757129&t="+ne...

如果有人遇到和我一样的问题,我刚刚找到了解决方法!

在你的笔记本中修改这段代码:

start=dt.datetime(2010,1,1)
end=dt.datetime(2017,1,1)
df = yf.download(tickers=['^GSPC'], start=start, end=end)