I have two DataFrames. The df1 has multi-index, the df2 has a standard index. How to merge them with repeating the values from df2 on every match of df2.index and df1.get.
Example
import pandas as pd
import numpy as np
idx1 = pd.MultiIndex.from_product([['bar', 'baz', 'foo'],['one','two']])
idx2 = ['bar', 'baz']
df1 = pd.DataFrame(np.random.randn(6, 2), index=idx1, columns=['A', 'B'])
df2 = pd.DataFrame(np.random.randn(2, 1), index=idx2, columns=['C'])
If df1 is
A B
bar one 0.690827 -0.627957
two -0.080936 -1.330712
baz one 1.395178 -0.099748
two -0.116789 0.723990
foo one 0.313067 0.853808
two 0.409727 -0.529002
and df2 is
C
bar -0.773924
baz 0.099662
How to get merge like?
A B C
bar one 0.690827 -0.627957 -0.773924
two -0.080936 -1.330712 -0.773924
baz one 1.395178 -0.099748 0.099662
two -0.116789 0.723990 0.099662
foo one 0.313067 0.853808 NaN
two 0.409727 -0.529002 NaN