0

So i'm trying to use this simple code to test TA-Lib and the other modules, but i'm having some problems:

from pandas_datareader import data, wb
import datetime
import talib
import numpy


start = datetime.datetime(2010,1,1)
end = datetime.datetime(2014,3,24)
ticker = "AAPL"
f = wb.pandas_datareader(ticker,'yahoo',start,end)

f['SMA_20'] = talib.SMA(numpy.asarray(f['Close']), 20)
f['SMA_50'] = talib.SMA(numpy.asarray(f['Close']), 50)
f.plot(y= ['Close','SMA_20','SMA_50'], title='AAPL Close & Moving Averages')

Gets the error AttributeError: module 'pandas_datareader.wb' has no attribute 'pandas_datareader' I successfully installed pandas-datareader, but i keep getting the error, did anyone else experience this?

Sile
  • 107
  • 1
  • 9
  • I'm not familiar with the particular syntax you're using, but the way given here works fine for me: http://pandas-datareader.readthedocs.io/en/latest/remote_data.html – JohnE Jan 16 '18 at 14:03
  • Taking a look at it, thanks! – Sile Jan 16 '18 at 14:32

1 Answers1

0

In the line f = wb.pandas_datareader(ticker,'yahoo',start,end), wb has no pandas_datareader within it. That is what your error says.

If you are looking at https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#yahoo-finance, then you should note that they import pandas_datareader.data with the alias web. In your case it has no alias, so you can call it with data.

I can guess that you are trying to do f = data.DataReader(ticker,'yahoo',start,end)

Borislav Aymaliev
  • 803
  • 2
  • 9
  • 20
  • Well, i tried that but i get 'pandas_datareader' is not defined' – Sile Jan 16 '18 at 14:31
  • Sorry...my bad. You should use only wb() without pandas_datareader. – Borislav Aymaliev Jan 16 '18 at 14:34
  • So i tried again and the previous problem seems to be solved, but right now i'm getting the error 'module object is not callable', did i make mistakes on the first line, calling pandas? – Sile Jan 16 '18 at 14:47
  • No, first line is ok. You imported data and wb there. Now the new problem is that wb is not a function. Maybe you need something from wb, but I have no idea what. Could you explain how you got this code? – Borislav Aymaliev Jan 16 '18 at 14:53
  • The new edit solved the problem, but it gave me the error 'Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access' – Sile Jan 16 '18 at 15:09
  • I got the code here: http://www.lampdev.org/programming/python/ta-lib-setup-and-example.html , i'm getting started to data analysis with Python and i had a bad time installing TA-Lib, so i searched for a quick example to see if TA-Lib was working properly! – Sile Jan 16 '18 at 15:10
  • I believe your new error is with another line in the code. Is it? – Borislav Aymaliev Jan 16 '18 at 15:15
  • Yeah. 'line 1716 series.name = label' – Sile Jan 16 '18 at 21:50