pandas datareader引发AttributeError:模块'pandas.io'没有属性'data' [英] pandas datareader raises AttributeError: module 'pandas.io' has no attribute 'data'

查看:156
本文介绍了pandas datareader引发AttributeError:模块'pandas.io'没有属性'data'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在尝试的代码

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'

我正在使用Anaconda,Python3.x.这是熊猫问题还是我的系统问题?

I am using Anaconda, Python 3.x . Is this a problem with Pandas or some issue with my system?

推荐答案

pandas已删除该功能,现在以其他软件包的形式提供(

pandas has removed that functionality and it is now offered as a different package (link):

DataReader删除了pandas.io.data子包,目的是使用 可单独安装的pandas-datareader软件包.这将允许 数据模块独立更新到您的熊猫安装. pandas-datareader v0.1.1的API与pandas v0.16.1中的API相同. (GH8961)

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

具有以下内容:

from pandas_datareader import data, wb

使用pip install pandas-datareader安装 pandas_datareader 并用以下代码替换代码:

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

这篇关于pandas datareader引发AttributeError:模块'pandas.io'没有属性'data'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆