Pandas- how to do merge on multiple columns including index
<p>I want to perform a merge in pandas on more than one column, where one of the columns is an index column.</p>

<p>Here are example dataframes:</p>

<pre><code>    df1 = pd.DataFrame(np.random.rand(4,4), columns=list('ABCD'))
    df2 = pd.DataFrame(np.random.rand(4,4), columns=list('EFGH'), index= [5,2,4,1])
    df1['E'] = ['hello','hello','hello','world']
    df2['E'] = ['world','world','hello','hello']
</code></pre>

<p>I want to perform an inner merge on the index and column E, so that it will return only one row:(index,E) = (1,'hello').</p>

<p>what about this?</p>

<pre><code>In [82]: pd.merge(df1.reset_index(), df2.reset_index(), on=['index','E']).set_index('index')
Out[82]:
              A        B         C         D      E        F         G         H
index
1      0.516878  0.56163  0.082839  0.420587  hello  0.62601  0.787371  0.121979
</code></pre>

python pandas merge