Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
866 views
in Technique[技术] by (71.8m points)

python - pandas datareader raises AttributeError: module 'pandas.io' has no attribute 'data'

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:Anacondalibsite-packagesspyderlibwidgetsexternalshellsitecustomize.py", line 714, in runfile
    execfile(filename, namespace)

  File "D:Anacondalibsite-packagesspyderlibwidgetsexternalshellsitecustomize.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

pandas has removed that functionality and it is now offered as a different package (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 the following:

from pandas_datareader import data, wb

Install pandas_datareader with pip install pandas-datareader and replace the code with the following:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...