title: Pandas DataFrame Self-Join on Key1 == Key1 and Key2 +1 == Key2
body: <p>Is there a way to alter a key during <code>pandas.merge()</code>?</p>
  
  <p>I'm trying to join <code>data</code> to itself on <code>left.person == right.person</code> and <code>left.record +1 == right.record</code>, so I can fill delta with datetime difference <code>right.date - left.date</code>.</p>
  
  <p>I'm on <code>Python 3.5.1 | IPython 4.1.2 | Anaconda custom (64-bit) | Windows 7</code></p>
  
  <pre><code>In[38]: data.info()
  &lt;class 'pandas.core.frame.DataFrame'&gt;
  RangeIndex: 11185856 entries, 0 to 11185855
  Data columns (total 4 columns):
  person    int64
  record    int64
  date      datetime64[ns]
  delta     datetime64[ns]
  dtypes: datetime64[ns](2), int64(2)
  memory usage: 341.4 MB
  
  In[39]: data.head(5)
  Out[37]: 
     person  record       date delta
  0       1       1 2015-08-01   NaT
  1       1       2 2015-10-18   NaT
  2       1       3 2016-02-06   NaT
  3       2       1 2015-04-18   NaT
  4       2       2 2015-07-11   NaT
  </code></pre>
  
  <p>This was trivial for me in SQL, but after reading pages of pandas-docs on merging and concatenation I'm still not getting it.</p>