I am trying to pull current price data for a list of stocks into a pandas dataframe. I am trying to pull the data using a loop into a dataframe in which the rows are the list items and the column is the current price. This loop keeps replacing all of the values in the Price column with the current price of the last stock in the list (JNJ 178.29). How do I fix this?
Input:
Target_Equities_List = ["MSFT",
"K",
"JNJ"]
Target_Frame = pd.DataFrame(index=Target_Equities_List)
for ticker in Equities_List:
yahoo_financials = YahooFinancials(ticker)
json_obj_price = yahoo_financials.get_stock_price_data()
current_price = json_obj_price[ticker]['regularMarketPrice']
Target_Frame["Price"] = current_price
Output:
Price
MSFT 178.29
K 178.29
JNJ 178.29
Thank you all!