pandas datareader 引发 AttributeError:模块“pandas.io”没有属性“data”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40816169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pandas datareader raises AttributeError: module 'pandas.io' has no attribute 'data'
提问by Debdipta Majumdar
This is a code I am trying
这是我正在尝试的代码
import matplotlib.pyplot as plt
import pandas as pd
ticker = 'GLD'
begdate = '2014-11-11'
enddate = '2016-11-11'
data1 = pd.io.data.DataReader(ticker,'yahoo',dt.datetime(2014,11,11),dt.datetime(2016,11,11))
gld_df = pd.DataFrame(data1)
date_df = pd.to_datetime(list(gld_df.index))
adj_close_df = list(gld_df["Adj Close"])
plt.plot(date_df,adj_close_df)
plt.title("SPDR Gold Shares ")
Its giving me the below error. Few days back, there was no error when I had tried the same code.
它给了我以下错误。几天前,当我尝试相同的代码时没有错误。
runfile('D:/Quant/MSQF/4 - Algorithms 1/3-Sorting/Mini Project 2_v2.py', wdir='D:/Quant/MSQF/4 - Algorithms 1/3-Sorting')
Traceback (most recent call last):
File "<ipython-input-10-db75eb5622f8>", line 1, in <module>
runfile('D:/Quant/MSQF/4 - Algorithms 1/3-Sorting/Mini Project 2_v2.py', wdir='D:/Quant/MSQF/4 - Algorithms 1/3-Sorting')
File "D:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
execfile(filename, namespace)
File "D:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/Quant/MSQF/4 - Algorithms 1/3-Sorting/Mini Project 2_v2.py", line 18, in <module>
data1 = pd.io.data.DataReader(ticker,'yahoo',dt.datetime(2014,11,11),dt.datetime(2016,11,11))
AttributeError: module 'pandas.io' has no attribute 'data'
I am using Anaconda, Python 3.x . Is this a problem with Pandas or some issue with my system?
我正在使用 Anaconda,Python 3.x。这是 Pandas 的问题还是我的系统的问题?
回答by ayhan
pandas has removed that functionality and it is now offered as a different package (link):
pandas 已删除该功能,现在作为不同的包(链接)提供:
DataReader The sub-package pandas.io.data is removed in favor of a separately installable pandas-datareader package. This will allow the data modules to be independently updated to your pandas installation. The API for pandas-datareader v0.1.1 is the same as in pandas v0.16.1. (GH8961)
You should replace the imports of the following:
from pandas.io import data, wbWith the following:
from pandas_datareader import data, wb
DataReader 子包 pandas.io.data 被删除,以支持单独安装的 pandas-datareader 包。这将允许数据模块独立更新到您的 Pandas 安装。pandas-datareader v0.1.1 的 API 与 pandas v0.16.1 中的相同。(GH8961)
您应该替换以下内容的导入:
from pandas.io import data, wb具有以下内容:
from pandas_datareader import data, wb
Install pandas_datareaderwith pip install pandas-datareaderand replace the code with the following:
pandas_datareader使用pip install pandas-datareader以下代码安装并替换代码:
from pandas_datareader import data
import datetime as dt
ticker = 'GLD'
begdate = '2014-11-11'
enddate = '2016-11-11'
data1 = data.DataReader(ticker,'yahoo',dt.datetime(2014,11,11),dt.datetime(2016,11,11))
回答by jprockbelly
My guess is you updated pandas to a newer version which no longer supports io.data
我的猜测是您将 Pandas 更新为不再支持 io.data 的较新版本
See here for fix http://pandas.pydata.org/pandas-docs/stable/remote_data.html
在这里查看修复 http://pandas.pydata.org/pandas-docs/stable/remote_data.html
回答by cel
If you import it directly, you get a more verbose import error:
如果直接导入,会得到更详细的导入错误:
from pandas.io.data import DataReader
ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import
from pandas.io import data, wbtofrom pandas_datareader import data, wb.
导入错误:pandas.io.data 模块被移动到一个单独的包 (pandas-datareader)。安装 pandas-datareader 包(https://github.com/pydata/pandas-datareader)后,您可以将导入更改
from pandas.io import data, wb为from pandas_datareader import data, wb.
回答by An Se
You need to do
你需要做
import pandas.io.data as web
then you can easily execute
然后你可以轻松地执行
web.DataReader(stuff)
Also, don't forget to import datetime as dtotherwise you'll catch another exception. Also, I've just was late for 1 sec :(
另外,不要忘记,import datetime as dt否则你会捕捉到另一个异常。另外,我只是迟到了 1 秒 :(
回答by Leon
I have the same issue, here is the solution:
我有同样的问题,这是解决方案:
pip install pandas_datareader
Change import pandas.io.datato from pandas_datareader import data, wb
更改import pandas.io.data为from pandas_datareader import data, wb
Use data.DataReader()to get data from Internet
用于data.DataReader()从 Internet 获取数据
updated*
更新*
good luck~~
祝你好运~~
回答by Munir Hoque
Well, you just need 2 things First uninstall the lib -
好吧,你只需要两件事首先卸载 lib -
pip uninstall pandas-datareader
And then need to install it using pip3(Please notice it is pip3)
然后需要使用pip3安装它(请注意它是pip3)
pip3 install pandas-datareader
And then use -
然后使用 -
from pandas_datareader import data, wb
#..............
#................
data.DataReader()

