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

后端 未结 6 891
长发绾君心
长发绾君心 2020-12-11 07:22

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 =         


        
相关标签:
6条回答
  • 2020-12-11 07:43

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

    0 讨论(0)
  • 2020-12-11 07:46

    Well, you just need 2 things First uninstall the lib -

    pip uninstall pandas-datareader
    

    And then need to install it using pip3 (Please notice it is pip3)

    pip3 install pandas-datareader
    

    And then use -

    from pandas_datareader import data, wb
    #..............
    
    #................
    data.DataReader()
    
    0 讨论(0)
  • 2020-12-11 07:46

    I have the same issue, here is the solution:

    pip install pandas_datareader
    

    Change import pandas.io.data to from pandas_datareader import data, wb

    Use data.DataReader() to get data from Internet

    updated*

    good luck~~

    0 讨论(0)
  • 2020-12-11 07:49

    My guess is you updated pandas to a newer version which no longer supports io.data

    See here for fix http://pandas.pydata.org/pandas-docs/stable/remote_data.html

    0 讨论(0)
  • 2020-12-11 07:52

    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))
    
    0 讨论(0)
  • 2020-12-11 07:58

    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 dt otherwise you'll catch another exception. Also, I've just was late for 1 sec :(

    0 讨论(0)
提交回复
热议问题