title: self-join with Pandas
body: <p>I would like to perform a self-join on a Pandas dataframe so that some rows get appended to the original rows. Each row has a marker 'i' indicating which row should get appended to it on the right.</p>
  
  <pre><code>d = pd.DataFrame(['A','B','C'], columns = ['some_col'])
  d['i'] = [2,1,1]
  
  In [17]: d
  Out[17]: 
    some_col  i
  0        A  2
  1        B  1
  2        C  1
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>  some_col  i some_col_y
  0        A  2          C
  1        B  1          B
  2        C  1          B
  </code></pre>
  
  <p>That is, row 2 gets appended to row 0, row 1 to row 1, row 1 to row 2 (as indicated by i).</p>
  
  <p>My idea of how to go about it was</p>
  
  <pre><code>pd.merge(d, d, left_index = True, right_on = 'i', how = 'left')
  </code></pre>
  
  <p>But it produces something else altogether. How to do it correctly?</p>