I have two dataframes in pandas, sample_df and new_df. They both contain stock returns for different time periods, where some time periods overlap. I want to merge them.
sample_df range from 2010-07-21 to 2017-12-29
new_df range from 2010-07-15 to 2014-09-23
How can I merge these two data frames together, where the dates are not overlapping it will fill NaN value or 0.
Both dateframes has date as their index.
My dataframes:
print(new_df)
date 11061
2010-07-14 NaN
2010-07-15 0.020321
2010-07-16 0.036075
2010-07-19 0.018263
2010-07-20 0.010312
... ...
2014-09-17 -0.010791
2014-09-18 -0.002048
2014-09-19 0.018833
2014-09-22 -0.005690
2014-09-23 0.006410
1034 rows × 1 columns
print(sample_df)
date 10113
2010-07-21 NaN
2010-07-22 0.029150
2010-07-23 0.011085
2010-07-26 0.004747
2010-07-27 -0.004730
... ...
2017-12-22 0.002216
2017-12-26 -0.004073
2017-12-27 -0.000170
2017-12-28 0.004080
2017-12-29 0.005617
1570 rows × 1 columns
I have tried
m = sample_df.join(new_df)
print(m)
But this does not work.
Any tips, thanks! :)