Code to collect data from Yahoo is not working

can someone help me with this code:

from pandas_reader import data as wb

tickers = [“PG”, “MSFT”, “T”, “F”, “GE”]
new_data = pd.DataFrame()
for t in tickers:
new_data[t] = wb.DataReader (t, data_source = “yahoo”, start = “1995-1-1”)[“Adj Close”]

I get these errors:

error 1:


ModuleNotFoundError Traceback (most recent call last)
Cell In[113], line 1
----> 1 from pandas_reader import data as wb

ModuleNotFoundError: No module named ‘pandas_reader’

Error 2:
ameError Traceback (most recent call last)
Cell In[106], line 4
2 new_data = pd.DataFrame()
3 for t in tickers:
----> 4 new_data[t] = wb.DataReader (t, data_source = “yahoo”, start = “1995-1-1”)[“Adj Close”]

NameError: name ‘wb’ is not defined

See this post here. Both sections apply to your post. Additionally, in regards to the second section about formatting, the traceback should also be posted as a code block on forums such as this.

Note that your post looks a lot like the StackOverflow post ‘Python pandas datareader no longer works for yahoo-finance changed url’. Or this StackOverflow post ‘Function from pandas_datareader doesn’t work’. Or this Python forum post ‘Problem with datareader’. When you find a pertinent place to post about this you’ll want to include what did you try in regards to them & point out exactly how your post differs from those.
Please read Getting good answers to your questions. Pay particular attention to the section ‘Search, and Research’ at How do I ask a good question? , linked at the bottom there.

1 Like