2

I am trying to get data from yahoo of stocks of a company through the code. But i am getting an ImportError at pandas_datareader.data where is says ImportError: cannot import name 'StringIO' Please help I am new to this...and already spent 4 hrs but could not resolve.

I have even tried

import io 
from io import StringIO

still getting the same error..!!

import datetime as dt 
import matplotlib.pyplot as plt 
from matplotlib import style 
import pandas as pd 
import pandas_datareader.data as web 



style.use('ggplot')
start = dt.datetime(2018,1,1)
end = dt.datetime(2018,12,31)

df = web.datareader('TSLA','yahoo',start,end)
print(df.head(5))

Error:-

Traceback (most recent call last):
  File "C:\Users\JAILANCHAL\Desktop\tut.py", line 5, in <module>
    import pandas_datareader.data as web 
  File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
    from .data import (DataReader, Options, get_components_yahoo,
  File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
    from pandas_datareader.av.forex import AVForexReader
  File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
    from pandas_datareader.base import _BaseReader
  File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\base.py", line 11, in <module>
    from pandas.compat import StringIO, bytes_to_str
ImportError: cannot import name 'StringIO'
Vasu Deo.S
  • 1,820
  • 1
  • 11
  • 23
jai arora
  • 21
  • 2
  • What versions of Python and pandas and pandas_datareader are you using? For me, I get an error here: `df = web.datareader('TSLA','yahoo',start,end)`. – norok2 Jul 20 '19 at 12:02
  • I am using python 3.5.4 with pandas 0.25 and pandas_datareader 0.7. I am also getting the error at the same line of code. – jai arora Jul 20 '19 at 13:01
  • If `from io import StringIO` works, you could perhaps try a different version of `pandas`, as it looks like the issue is with that package. – norok2 Jul 20 '19 at 13:05
  • I switched to pandas 0.19.1 and pandas_datareader 0.6.0 . It has started working with just 'import pandas_datareader.data as web' . 'from io import StringIO' is no longer required. Also, I have come across that many the data sources have been deprecated. But Quandl is working fine for me. Robinhood, morningstar, yahoo, google and even av didnt work for me. THANKS for help !! – jai arora Jul 20 '19 at 16:44

0 Answers0