Below is the code. Whenever I try to run this it says type error: string indices must be integers, #not "str"
import datetime as dt
import matplotlib.pyplot as plt
import pandas as pd
import pandas_datareader as pdr
start = dt.datetime.now() - dt.timedelta(days = 365*3)
end = dt.datetime.now()
stocks = ['VOO', 'QQQ']
df = pdr.get_data_yahoo(stocks, start, end)
df.head()
I am trying to get data from yahoo finance on VOO and QQQ stock price from the last three years to today. I am getting a large error code that ends with string indices must be integers, not 'str'
Maybe you can use
yfinanceas replacement ofpandas_datareader:Output: