Feb-02-2023, 01:28 PM
I am trying to read stock data using panda's DataReader and getting an error that I am not sure I understand.
The data source : 'yahoo' is found at the following url:
https://pandas-datareader.readthedocs.io...data-yahoo
The data source : 'yahoo' is found at the following url:
https://pandas-datareader.readthedocs.io...data-yahoo
import pandas_datareader.data as web bac = web.DataReader('BAC', 'yahoo', start='2019-09-10', end='2019-10-09')
Error:TypeError Traceback (most recent call last)
Input In [13], in <cell line: 6>()
3 end_date = datetime.datetime(2016, 1, 1)
4 #Bank of America
5 #BAC = data.DataReader('BAC', 'yahoo', start='2006-01-01', end='2016-01-01')
----> 6 ge = web.DataReader('BAC', 'yahoo', start='2019-09-10', end='2019-10-09')
File C:\Anaconda\lib\site-packages\pandas\util\_decorators.py:207, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
205 else:
206 kwargs[new_arg_name] = new_arg_value
--> 207 return func(*args, **kwargs)
File C:\Anaconda\lib\site-packages\pandas_datareader\data.py:370, in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
367 raise NotImplementedError(msg)
369 if data_source == "yahoo":
--> 370 return YahooDailyReader(
371 symbols=name,
372 start=start,
373 end=end,
374 adjust_price=False,
375 chunksize=25,
376 retry_count=retry_count,
377 pause=pause,
378 session=session,
379 ).read()
381 elif data_source == "iex":
382 return IEXDailyReader(
383 symbols=name,
384 start=start,
(...)
390 session=session,
391 ).read()
File C:\Anaconda\lib\site-packages\pandas_datareader\base.py:253, in _DailyBaseReader.read(self)
251 # If a single symbol, (e.g., 'GOOG')
252 if isinstance(self.symbols, (string_types, int)):
--> 253 df = self._read_one_data(self.url, params=self._get_params(self.symbols))
254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
255 elif isinstance(self.symbols, DataFrame):
File C:\Anaconda\lib\site-packages\pandas_datareader\yahoo\daily.py:153, in YahooDailyReader._read_one_data(self, url, params)
151 try:
152 j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
--> 153 data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
154 except KeyError:
155 msg = "No data fetched for symbol {} using {}"
TypeError: string indices must be integers