Suppose I have the following two dataframes:
np.random.seed(1)
annual = pd.DataFrame(data=np.random.random((2, 4)), index=index, columns=pd.period_range(start="2015", end="2018", freq="Y"))
quarterly = pd.DataFrame(data=np.random.random((2,3)), index=index, columns=pd.period_range('2019', freq='Q', periods=3))
Annual
:
2015 2016 2017 2018
A 0.417022 0.720324 0.000114 0.302333
B 0.146756 0.092339 0.186260 0.345561
Quarterly
:
2019Q1 2019Q2 2019Q3
A 0.396767 0.538817 0.419195
B 0.685220 0.204452 0.878117
Is it possible that I combine the two dataframes so that the resultant dataframe df
looks like something below? If not, are there workarounds that allow me to merge the two dataframes so that I can do something like df['2019Q2'] - df['2018']
?
2015 2016 2017 2018 2019Q1 2019Q2 2019Q3
A 0.417022 0.720324 0.000114 0.302333 0.396767 0.538817 0.419195
B 0.146756 0.092339 0.186260 0.345561 0.685220 0.204452 0.878117