Unexpert opinion here after fiddling around with your code and chatgpt.
For your particular setup, there is some difference in the .columns
between the data frames.
>>> df.columns
Index(['ds', 'y'], dtype='object')
>>> ld.columns # lululemon_data
MultiIndex([('ds', ''),
( 'y', 'LULU')],
names=['Price', 'Ticker'])
I am not sure what the exact difference is, but it's probably used by yfinance
to differentiate between multiple tickers. From the documentation for yfinance.download
,
multi_level_index: bool
Optional. Always return a MultiIndex DataFrame? Default is True
I toggled multi_level_index
to False
, which seems to fix your code.
lululemon_data = yf.download(ticker, start='2007-07-27', multi_level_index=False) # Lululemon IPO date
For other cases where getting the underlying library cannot output an applicable type, maybe this thread can help to flatten a MultiIndex
.