I would like to fill each row of a column of my dataframe based on the entries in 2 other columns, in particular I want to fill each row with the corresponding stock price of the corresponding ticker for that stock and the date, like so
dict1 = [{'ticker': 'AAPL','date': date(2016, 3, 1),'Price': 'NaN'},
{'ticker': 'MSFT','date': date(2017, 12, 1), 'Price': 'NaN'}]
df1 = pd.DataFrame(dict1)
df1.index=df1['ticker']
df1.loc['AAPL','Price'] = web.DataReader(df1.loc['AAPL','ticker'], 'iex', df1.loc['AAPL','date'], df1.loc['AAPL','date']).close[0]
I am struggling to find a way to automate this with a for loop, apply, or map. Can anyone suggest an approach?
I have asked a similar question, where 'map' worked (for just 1 column) but I am not sure how to extend that to 2 reference columns.
Filling a pandas column based on another column
Note, the function used to pull the name comes from here:
import pandas_datareader.data as web