Reputation: 507
I am trying to import fundamental data for multiple stocks with yfinance
import yfinance as yf
ticker = yf.Ticker('AAPL')
ticker.info["priceToBook"]
Returns Apples P/B of 15.9 as expected
But what if I want to loop through a list of tickers, like
tickers = ['AAPL', 'ORCL', 'TSLA']
and save them to a df or list
Upvotes: 0
Views: 2378
Reputation: 13097
You can just loop through the tickers you want and add them to a dictionary (or whatever you want)
dictionary = {}
tickers = ['AAPL', 'ORCL', 'TSLA']
for t in tickers:
ticker = yf.Ticker(t)
dictionary[t] = ticker.info["priceToBook"]
Upvotes: 1