Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

yf.download returns multi-index columns #2193

Closed
coulanuk opened this issue Dec 24, 2024 · 2 comments
Closed

yf.download returns multi-index columns #2193

coulanuk opened this issue Dec 24, 2024 · 2 comments

Comments

@coulanuk
Copy link

Upgraded to yfinance 2.51 this week
yf.Download for a single ticker now produces columns with an un-wanted multi-index with an altered column order (CHLOV)

Example
start_date = '2023-01-01'
end_date = datetime.now().strftime('%Y-%m-%d')
ticker = 'TSLA'
df = yf.download(tickers=[ticker], start=start_date, end=end_date)

df.columns
MultiIndex([( 'Close', 'TSLA'),
( 'High', 'TSLA'),
( 'Low', 'TSLA'),
( 'Open', 'TSLA'),
('Volume', 'TSLA')],
names=['Price', 'Ticker'])

Workaround
df.columns = df.columns.to_flat_index()
... and then rename and re-order columns to OHLCV

@coulanuk
Copy link
Author

Better Workaround
df.columns = df.columns.get_level_values(0)

@coulanuk
Copy link
Author

Am closing this issue as the API has a solution.
df = yf.download(tickers=[ticker], start=start_date, end=end_date, multi_level_index=False)
Seems we have lost AdjClose ?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant