I haven't had problems with such DataFrame operations until now.
What I'm trying to achieve, is to get a DataFrame, containing daily data for a few years period and hourly data for the last 5 days. My code (fully running):
import yfinance as yf
import pandas as pd
ticker = yf.Ticker('TSLA')
fine = ticker.history(period='5d', interval='60m')
fine.index = fine.index.tz_convert('UTC').tz_localize(None)
print(fine)
coarse_end_date = fine.index[0].date()
coarse = ticker.history(start='2019-01-01', end=coarse_end_date, interval='1d')
print(coarse)
yfdata = pd.merge(coarse, fine, how='inner', left_index=True, right_index=True)
print(yfdata)
Naturally, I'm trying to merge on both indexes (removing tz data from fine index first). What I get in result is an empty DataFrame:
Empty DataFrame
Columns: [Open_x, High_x, Low_x, Close_x, Volume_x, Dividends_x, Stock Splits_x, Open_y, High_y, Low_y, Close_y, Volume_y, Dividends_y, Stock Splits_y]
Index: []
As you can see, merge operation splits similar DataFrame columns into _x and _y columns, and then, of course, there are no common values, hence the empty DataFrame.
I've tried assigning time to coarse dates, resetting indexes and merging on date column, renaming indexes, and other desperate stuff, but nothing worked.
Maybe someone has an idea of what's happening, I would highly appreciate your help
I've tried some more desperate stuff, and apparently, I needed to specify columns I want to merge. Also, outer join method is required here.
yfdata = pd.merge(coarse, fine, how='outer', on=coarse.columns.to_list(), left_index=True, right_index=True)