3

I have been trying to pull data from Yahoo Finance and I keep getting this strange error.

So I run this code :

#Importing Modules/Libraries
import pandas as pd

pd.core.common.is_list_like = pd.api.types.is_list_like

from pandas_datareader import data, wb

import fix_yahoo_finance as yf

yf.pdr_override()

import numpy as np

import datetime

import seaborn as sns

import matplotlib.pyplot as plt



And I get a feedback from my console with this error :
#Importing Modules/Libraries

import pandas as pd

pd.core.common.is_list_like = pd.api.types.is_list_like

from pandas_datareader import data, wb

import fix_yahoo_finance as yf

yf.pdr_override()

import numpy as np

import datetime

import seaborn as sns

import matplotlib.pyplot as plt

#Importing Historical data from yahoo finance

tickers = 

['XSLV','SMLV','XMLV','USMV','LGLV','SPLV','PRFZ','PXSC','FNDB','PXMC','PRF','QQ

EW','RSP','EQWL','EQAL','EWMC','EWSC',


'DWAS','MMTM','PDP','DWAQ','QUAL','SPHQ','^PHB','ACWV','IDLV','EELV','PDN','PXH'

,'QWLD','IQLT','IQDF','IDMO','EEMO',

  'PIZ','PIE']

indices = pd.DataFrame()

for t in tickers:indices[t]=data.get_data_yahoo(t, data_source='yahoo',start='2016-1-1')['Adj Close']

Output:

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

Traceback (most recent call last):

 File "<input>", line 18, in <module>

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\fix_yahoo_finance\__init__.py", line 202, in download

'Close', 'Adj Close', 'Volume']]

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\frame.py", line 2682, in __getitem__

return self._getitem_array(key)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\frame.py", line 2726, in _getitem_array

indexer = self.loc._convert_to_indexer(key, axis=1)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexing.py", line 1308, in _convert_to_indexer

obj, kind=self.name)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexes\multi.py", line 1968, in _convert_listlike_indexer

_, indexer = self.reindex(keyarr, level=level)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexes\multi.py", line 2057, in reindex

keep_order=False)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexes\base.py", line 3969, in _join_level

ngroups = 1 + new_lev_labels.max()

File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\numpy\core\_methods.py", line 26, in _amax

return umr_maximum(a, axis, None, out, keepdims)

ValueError: zero-size array to reduction operation maximum which has no identity.
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Weirdly enough I've been getting the same issue since the same time you have. I've noticed that this error comes when the return from yahoo is None. This either (maybe) happens because: Yahoo instability, too many requests or the ticker name is wrong (for instance, brazilian tickers I had to add ".SA" at the end) – mrbTT Aug 20 '18 at 21:06
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Aug 21 '18 at 09:46
  • Hi halfer.thanks for your time and for sharing your experience..I copy and paste my ticker symbols directly from yahoo finance and double check always for typos..I doubt whether its a ticker problem since i practically copy and paste ticker symbols from yahoo finance directly. – DeepLearningBeast Aug 21 '18 at 14:21
  • Has anyone been able to resolve this issue? I'm currently having that same problem with Yahoo tickers. – gbade_ Oct 14 '18 at 21:38

2 Answers2

0

This is a rate limit set on Yahoo. You can do try and pass to avoid value error.

Something like this :

for ticker in tickers1:
    try:
        df = yahoo.download(self.TICK_SYMBOLS, start = self.START, end = datetime.now())
        df.reset_index(inplace = True)
        df.set_index("Date", inplace = True)

    except ValueError:
        pass
Gabe H. Coud
  • 175
  • 2
  • 14
0

You need to specify end_date. Also date has to be in 'YYYY-MM-DD' format.

import fix_yahoo_finance as yahoo

spx_df = yahoo.download("^GSPC", "2015-01-01", "2019-04-28')
spx_df.Close.plot()

enter image description here

Vlad Bezden
  • 83,883
  • 25
  • 248
  • 179