I'm just starting using python and when I try running this code that's supposed to download the tickers a Key Error date appears.
import pandas as pd
import numpy as np
import datetime as dt
import math
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
stock_prices= pd.DataFrame()
tickers= ['tsla', 'appl', 'msft', 'goog', '^IXIC']
for i in tickers:
stock_prices[i]= wb.DataReader(i, data_source='yahoo', start= s, end= e)['Adj Close']
CodePudding user response:
Replace APPL
by AAPL
.
import pandas as pd
import numpy as np
import datetime as dt
import math
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
stock_prices= pd.DataFrame()
tickers= ['TSLA', 'AAPL', 'MSFT', 'GOOG', '^IXIC']
s = dt.datetime(2022,9,1)
e = dt.datetime(2022,9,9)
for i in tickers:
stock_prices[i]= wb.DataReader(i, data_source='yahoo', start= s, end= e)['Adj Close']
stock_prices