I want to store the "info" from a list of the SP500 symbols in a Pandas DataFrame.
I can do this one at a time (df1, df2,...) and then append all into one DataFrame (df):
but would like to have a function that automates this by iterating through a list of symbols and appends new rows each time to 'df'.
Any ideas?? Thanks!
Try this:
import pandas as pd
import yfinance as yf
l = ['AAPL', 'MMM']
df_list = []
for t in l:
df_list.append(pd.DataFrame([yf.Ticker(t).info]))
df = pd.concat(df_list)
print(df)