Help with pandas-datareader for Visualizing Tech Stocks in "Analyze Financial Data with Python"

I’m trying to run the off-platform project using Jupyter Notebooks and I have pandas-datareader installed. However, when I run the following, I get an error.

symbols = ['MSFT','AMZN','AAPL','GOOG','FB']
start_date = datetime.datetime(2019,1,1)
end_date = datetime.datetime(2019,7,1)
stock_data = web.get_data_yahoo(symbols,start_date,end_date)
print(stock_data.head())

Here’s the error. This error has been noted by other users, but there was no apparent solution noted in the previous thread. Can somebody give me some help? Thanks.

---------------------------------------------------------------------------
RemoteDataError                           Traceback (most recent call last)
<ipython-input-18-b17e3a4d0dcf> in <module>
      2 start_date = datetime.datetime(2019,1,1)
      3 end_date = datetime.datetime(2019,7,1)
----> 4 stock_data = web.get_data_yahoo(symbols,start_date,end_date)
      5 print(stock_data.head())

~/anaconda3/envs/stocks/lib/python3.8/site-packages/pandas_datareader/data.py in get_data_yahoo(*args, **kwargs)
     84 
     85 def get_data_yahoo(*args, **kwargs):
---> 86     return YahooDailyReader(*args, **kwargs).read()
     87 
     88 

~/anaconda3/envs/stocks/lib/python3.8/site-packages/pandas_datareader/base.py in read(self)
    256             df = self._dl_mult_symbols(self.symbols.index)
    257         else:
--> 258             df = self._dl_mult_symbols(self.symbols)
    259         return df
    260 

~/anaconda3/envs/stocks/lib/python3.8/site-packages/pandas_datareader/base.py in _dl_mult_symbols(self, symbols)
    275         if len(passed) == 0:
    276             msg = "No data fetched using {0!r}"
--> 277             raise RemoteDataError(msg.format(self.__class__.__name__))
    278         try:
    279             if len(stocks) > 0 and len(failed) > 0 and len(passed) > 0:

RemoteDataError: No data fetched using 'YahooDailyReader'

Did you see this/try this on S.O.?

It seems like one has to update/pip install an update to yahoo finance. And, while I’ve not done this project/looked at the data, maybe some of the companies don’t exist anymore(?)

Thanks for the pointer, but these stocks were all available during 2019. I ran the fix for yfinance, but still the same error.

Hmm. Okay. Let me think on this…

If you google this very issue a LOT comes up in the search results…going back 4 years or more. I really think this is an issue with Yahoo’s API & the endpoints have changed.
See here.

And, this too.

I’m going to create a bug report about this issue. Maybe CC can change the project specs on where to grab the finance data and not get it from Yahoo any longer.

Also, UPDATE: Yahoo Finance Daily Data through icharts no longer available · Issue #5 · ScottfreeLLC/AlphaPy · GitHub

I tired it on a different computer and still got the same errors. I also got these following warnings:

`/Users/cgates/opt/anaconda3/envs/stock/lib/python3.8/site-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: 'MSFT', replacing with NaN.
  warnings.warn(msg.format(sym), SymbolWarning)
/Users/cgates/opt/anaconda3/envs/stock/lib/python3.8/site-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: 'AMZN', replacing with NaN.
  warnings.warn(msg.format(sym), SymbolWarning)
/Users/cgates/opt/anaconda3/envs/stock/lib/python3.8/site-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: 'AAPL', replacing with NaN.
  warnings.warn(msg.format(sym), SymbolWarning)
/Users/cgates/opt/anaconda3/envs/stock/lib/python3.8/site-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: 'GOOG', replacing with NaN.
  warnings.warn(msg.format(sym), SymbolWarning)
/Users/cgates/opt/anaconda3/envs/stock/lib/python3.8/site-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: 'FB', replacing with NaN.
  warnings.warn(msg.format(sym), SymbolWarning)`

It has nothing to do with the machine.

If you click on and read the information that I added above, it might provide you with some insights. Also, I submitted a bug report to CC.

2 Likes

I still haven’t been able to use DataReader to retrieve any of the stock info. However, I imported yahoo_fin and can use it’s get_data function to pass the tickers, start and end dates to get the data.

The problem now is that the data comes back as a dictionary with the keys being ticker symbols. Each corresponding value is a DataFrame with an date index and the open/high/low/close/adjclose columns. I think this more or less does what the Visualizing Tech Stocks exercise wants, but I haven’t been able to create subplots of the different stocks adjclose from the dictionary. Instead, I have to call out df[‘ticker’][‘adjclose’].plot() for each of the ticker symbols (i.e., 5 different lines for 5 different plots). Is there a way to plot the subplots for each key of the dictionary in one command?

Without seeing a sample of the dictionary/data, I’m going to guess here at what it looks like.

Remember, dictionaries are unordered. To plot them you’d have to sort by key or value before plotting.

You can use the .sorted() function to sort them by either key or value which will return a tuple, which you can then plot.

See: https://docs.python.org/2/library/collections.html#collections.OrderedDict

Or, if you want to sort the entire dictionary, you can use the .items() method which returns an iterable kind of dictionary object.

See here for a non documentation explanation: https://towardsdatascience.com/sorting-a-dictionary-in-python-4280451e1637

You would also have to use .zip() to unpack the pairs of tuples.

Here’s a really good Q&A:
https://stackoverflow.com/questions/37266341/plotting-a-python-dict-in-order-of-key-values