How to fix "string indices must be integers, not 'str'", that I am getting while practicing with Pandas DataReader?

765 Views Asked by At

Code:

import pandas as pd
import pandas_datareader.data as pdr
import datetime as dt
df = pdr.DataReader('MSFT','yahoo', start='2021-4-15', end='2023-04-14')
df.head()

O/P:

TypeError: string indices must be integers, not 'str'.

I was trying to get the stock data as dataframe using pandas datareader library, while practicing and learning.

but in O/P it's throwing error as

TypeError: string indices must be integers, not 'str'

How to fix it ? I have gone through the pd datareader documentation, where they also shown the exact code snippet.

1

There are 1 best solutions below

2
Vladimir Abramov On

You can try this approach:

from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override()

pdr.get_data_yahoo('MSFT',start='2021-4-15',end='2023-4-14')

That is how you can access the data until the issue with package will be solved.