title: Join pandas tables, keeping one index
body: <p>What I want to do is join two dataframes on columns and keep the index of one of them (but the index is unrelated to whether I join them or not).</p>
  
  <p>For example, if <code>df1</code> is the dataframe that has certain timestamps as its index that I would like to keep, then to join with <code>df2</code> on the 'key' column, my expected code would be</p>
  
  <pre><code>df3 = pd.merge(df1, df2, on='key', left_index=True)
  </code></pre>
  
  <p>I would then expect df3 to have all rows of df1 and df2 where <code>df3[key] == df1[key] == df2[key]</code> and <code>df3[key].index == df1[key].index</code>.</p>
  
  <p>However, this is not the case. In fact, you find that the index of <code>df3</code> is actually the index of <code>df2</code>. The reverse is true for <code>right_index=True</code>.</p>
  
  <p>I've considered submitting a bug report, but rereading the documentation leads me to believe that (while completely counter intuitive) this may not be incorrect behavior.</p>
  
  <p>What <em>is</em> the proper way to join two tables, keeping one of the indices?</p>
  
  <p>EDIT:</p>
  
  <p>I am doing an inner join on 'key'. That is not the issue. The issue is that I want the resulting rows to have the index of one of the dataframes.</p>
  
  <p>For example, if I have the following sets of data in two dataframes:</p>
  
  <pre><code>df1 = pd.DataFrame(np.arange(4).reshape(2,2))
  df2 = pd.DataFrame(np.arange(4).reshape(2,2), columns=[0,2])
  df2.index = df2.index.map(lambda x: x + 10)
  </code></pre>
  
  <p>That is,</p>
  
  <pre><code>&gt;&gt;&gt; df1
     0  1
  0  0  1
  1  2  3
  &gt;&gt;&gt; df2
      0  2
  10  0  1
  11  2  3
  </code></pre>
  
  <p>I can run <code>pd.merge(df1, df2, on=0)</code> which (as expected) yields</p>
  
  <pre><code>&gt;&gt;&gt; pd.merge(df1,df2,on=0)
     0  1  2
  0  0  1  1
  1  2  3  3
  </code></pre>
  
  <p>Notice, however, that <code>df2</code> has a different index. In my actual data, this is timestamp data that I want to keep. It isn't used in the joining at all, but it <em>does</em> need to persist. I <em>could</em> just add a column to <code>df2</code> to keep it around, but that isn't what I want to do. :)</p>
  
  <p>What I would like is to do something like <code>pd.merge(df1, df2, on=0, right_index=True)</code> and receive:</p>
  
  <pre><code>    0  1  2
  10  0  1  1
  11  2  3  3
  </code></pre>
  
  <p>However, I actually get the <strong><em>opposite</em></strong> of this:</p>
  
  <pre><code>&gt;&gt;&gt; pd.merge(df1,df2,on=0,right_index=True)
     0  1  2
  0  0  1  1
  1  2  3  3
  </code></pre>
  
  <p>while reversing them inexplicably works.</p>
  
  <pre><code>&gt;&gt;&gt; pd.merge(df1,df2,on=0,left_index=True)
      0  1  2
  10  0  1  1
  11  2  3  3
  </code></pre>