Hi All,
I am coming across below issue. I am trying to save the multiple tickers in the same dataframe and for that I am creating a dictionary to start with but I dont know how to conver the dictionary to datafam as when i conver it to dictionary , the ticker/symboe is treated as key and i want this key to become column along with open high low close. Please advice.
mport datetime as dt
import yfinance as yf
import pandas as pd
import numpy as np
data = pd.DataFrame
stocks = ["MSFT","AMZN","GOOG"]
ohlcv_dicdata = {}
for ticker in stocks:
ohlcv_dicdata[ticker] = yf.download(ticker,period="6mo")
df_from_dict = pd.DataFrame.from_dict(ohlcv_dicdata) ## gives errors
The data contains multiple index so it can't be done using dataframe.
You need to use pandas panel. Try this:
df_from_dict = pd.Panel.from_dict(ohlcv_dicdata)
Can read more about pandas panel here.