I have two dataframes, "bio" with monthly data, where I only need the column bio['Bio_Avg']. And another one "tc" with daily data. Both with Datetime index.
What I need is to merge both keeping daily granularity but adding monthly data repeating the value of the column bio['Bio_Avg'].
print(bio.head(5))
year month ncena ... contingency D Bio_Avg
Date ...
2019-12-01 2019 12 NaN ... NaN 1 38826.48
2019-11-01 2019 11 NaN ... NaN 1 33867.68
2019-10-01 2019 10 NaN ... NaN 1 31358.80
2019-09-01 2019 9 NaN ... NaN 1 29583.84
2019-08-01 2019 8 NaN ... NaN 1 27763.12
and
print(tc.head(5))
exchg_rate
2019-11-01 59.71
2019-11-02 59.74
2019-11-03 59.73
2019-11-04 59.70
2019-11-05 59.65
The expected result should be:
exchg_rate Bio_Avg
2019-11-01 59.71 33867.68
2019-11-02 59.74 33867.68
2019-11-03 59.73 33867.68
2019-11-04 59.70 33867.68
2019-11-05 59.65 33867.68
I've tried:
merge = pd.merge(tc, bio, left_index=True, right_index=True)
print(merge.head(5))
And I get:
exchg_rate year month ... contingency D Bio_Avg
2019-11-01 59.75 2019 11 ... NaN 1 33867.68
2019-12-01 59.94 2019 12 ... NaN 1 38826.48
Off course it keeps only the exact match with the date, but I loose the days in between. What could be an elegant way to solve this without breaking all dataframes?