简体   繁体   English

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

[英]Error when loading data using web.DataReader, yahoo finance

I try to load data using web.DataReader but I always get the error "RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/FB/history?period1=1325390400&period2=1577937599&interval=1d&frequency=1d&filter=history" .我尝试使用 web.DataReader 加载数据,但我总是收到错误“RemoteDataError:无法读取 URL: https://finance.yahoo.com/quote/FB/history?period1=1325390400&period2=1577937599&=interval=1d&frequencyhist&=interval=1d&frequencyhist “

I already used the following package updates and my code worked fine yesterday.我已经使用了以下 package 更新,昨天我的代码运行良好。 However today I still get the same error as before (ie, unable to read URL).但是今天我仍然遇到与以前相同的错误(即无法读取 URL)。

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

PS: I use Google Colab PS:我使用谷歌 Colab

Here is the full beginning of my code (including the error):这是我的代码的完整开头(包括错误):

!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 (most recent call last) in () ----> 1 data = web.DataReader(company, 'yahoo',start,end) () ----> 1 data = web.DataReader(company, 'yahoo',start,end) 中的 RemoteDataError Traceback(最后一次调用)

4 frames /usr/local/lib/python3.7/dist-packages/pandas_datareader/base.py in _get_response(self, url, params, headers) 179 msg += "\nResponse Text:\n{0}".format(last_response_text) 180 --> 181 raise RemoteDataError(msg) 182 183 def _get_crumb(self, *args): 4 帧 /usr/local/lib/python3.7/dist-packages/pandas_datareader/base.py in _get_response(self, url, params, headers) 179 msg += "\nResponse Text:\n{0}".format (last_response_text) 180 --> 181 raise RemoteDataError(msg) 182 183 def _get_crumb(self, *args):

RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/FB/history?period1=1325390400&period2=1577937599&interval=1d&frequency=1d&filter=history Response Text: b'\n \n \n \n Yahoo\n \n \n \n html {\n height: 100%;\n }\n body {\n background: #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 height: 100%;\n width: 100%;\n table-layout: fixed;\n border-collapse: collapse;\n border-spacing: 0;\n border: none;\n }\n h1 {\n font-size: 42px;\n font-weight: 400;\n color: #400090;\n }\np {\n color: #1A1A1A;\n }\n #message-1 {\n font-weight: bold;\n margin: 0;\n }\n #message-2 {\n display: inline-block;\n *display: inline;\n zoom: 1;\n max-width: 17em;\n _width: 17em;\n }\n \n \n document.write('&test=\'+encodeURIComponent(\'%\')+\'" width="0px" height="0px"/> 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 表格 {\n 高度:100%;\n 宽度:100%;\n 表格布局:固定;\n 边框折叠:折叠;\n 边框间距:0;\n边框:无;\n }\n h1 {\n 字体大小:42px;\n 字体粗细:400;\n 颜色:#400090;\n }\np {\n 颜色:#1A1A1A;\n } \n #message-1 {\n font-weight: bold;\n margin: 0;\n }\n #message-2 {\n display: inline-block;\n *display: inline;\n zoom: 1;\n 最大宽度: 17em;\n _width: 17em;\n }\n \n \n document.write('&test=\'+encodeURIComponent(\'%\')+\'" width=" 0px" 高度="0px"/> ');var beacon = new Image();beacon.src="//bcn.fp.yahoo.com/p?s=1197757129&t="+ne... ');var beacon = new Image();beacon.src="//bcn.fp.yahoo.com/p?s=1197757129&t="+ne...

If anyone faces the same issue as mine, I just found out how to solve it!如果有人面临与我相同的问题,我只是找到了解决方法!

Adapt this piece of code in your notebook:在你的笔记本中修改这段代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 pandas 数据阅读器加载雅虎财务数据 - Loading yahoo finance data from pandas datareader 未获取数据 Web.DataReader Panda - No data fetched Web.DataReader Panda 使用 Pandas Datareader 从 Yahoo Finance 获取股票数据时出现“TypeError: string indices must be integers” - "TypeError: string indices must be integers" when getting data of a stock from Yahoo Finance using Pandas Datareader 使用pandas web.DataReader从整个索引(例如DJIA)获取数据 - Grabbing data from entire index (e.g., DJIA) using pandas web.DataReader 如何在与 web.DataReader 相关的 Python 中修复此错误 - How to fix this error in Python related to web.DataReader 熊猫雅虎财务DataReader - Pandas yahoo finance DataReader Pandas DataReader 从雅虎财经获取股票报价时抛出日期错误 - Pandas DataReader Throws a Date Error When Getting Stock Quotes From Yahoo Finance 无法在 Python 中使用 pandas_datareader 检索雅虎财经股票数据 - Unable to retrieve Yahoo Finance stock data using pandas_datareader in Python 有没有办法使用 yahoo finance 从 pandas datareader 中提取历史期权数据? - Is there a way to pull historical options data using yahoo finance from pandas datareader? 使用 python pandas 的 Datareader 访问雅虎财经的关键统计网页 vs 默认雅虎财经的历史价格网页 - Using python pandas's Datareader for yahoo finance's key statistic web page vs default yahoo's finance's historial prices web page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM