I am trying to concatenate 2 dataframe df1 and df2 df1 is a multiindex dataframe and df2 has less rows than df1
import pandas as pd import numpy as np arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']] tuples = list(zip(*arrays)) index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second']) df1 = pd.DataFrame(np.random.randn(8), index=index) df1 Out[15]: 0 first second bar one -0.185560 two -2.358254 baz one 1.130550 two 1.441708 foo one -1.163076 two 1.776814 qux one -0.811836 two 0.389500 df2 = pd.DataFrame(data=[0,1,0,1],index=['bar','baz','foo', 'qux'],columns=['label']) df2 Out[18]: label bar 0 baz 1 foo 0 qux 1 The desired result would be something like:
df3 Out[18]: 0 label first second bar one -0.185560 0 two -2.358254 0 baz one 1.130550 1 two 1.441708 1 foo one -1.163076 0 two 1.776814 0 qux one -0.811836 1 two 0.389500 1