2016-11-26 73 views
1

這是我想大熊貓DataReader的提高AttributeError的:模塊「pandas.io」有沒有屬性「數據」

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 ") 

它給我下面的錯誤代碼。幾天前,當我嘗試了相同的代碼時沒有錯誤。

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' 

我使用的是Anaconda,Python 3.x。這是熊貓問題還是我的系統出現問題?

回答

3

大熊貓已刪除的功能,並且它現在提供了一個不同的包(link):

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, wb With: 

from pandas_datareader import data, wb 

pip install pandas-datareader 安裝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)) 
+1

僅供參考 - '''PIP安裝data_reader'''沒有爲我工作。它是'''pip安裝pandas_datareader''' –

+0

謝謝,我已更新該帖子。 – ayhan

0

如果直接導入一個新的版本,你會得到一個更詳細的導入錯誤:

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, wb to from pandas_datareader import data, wb .

0

你需要做的

import pandas.io.data as web 

,那麼你可以很容易地執行

web.DataReader(stuff) 

另外,不要忘了import datetime as dt否則你會趕上其他異常。另外,我剛剛是1秒:(後期

0

我有同樣的問題,這裏是解決方案:

pip install pandas_datareader 

變化import pandas.io.datafrom pandas_datareader import data, wb

使用data.DataReader()從Internet

更新獲取數據*

好運~~

+0

'$ pip install pandas-datareader' 請參閱https://pypi.python.org/pypi/pandas-datareader –

0

好吧,你只需要兩件事情 首先卸載的lib -

pip uninstall pandas-datareader 

然後需要使用PIP3安裝它(請注意這是PIP 3)

pip3 install pandas-datareader 

然後用 -

from pandas_datareader import data, wb 
#.............. 

#................ 
data.DataReader() 
相關問題