title: How do delete consecutive duplicate rows from pandas dataframe while also updating column values?
body: <p>I have the following data structure:</p>
  
  <pre><code>     |a       |b     |start_time  |end_time
  0    |aaba    |d     |11:26       | 11:27
  1    |aba     |c     |11:27       | 11:32
  2    |aba     |c     |11:32       | 11:34
  3    |cab     |ab    |11:34       | 11:35
  4    |aba     |c     |11:35       | 11:40
  </code></pre>
  
  <p>I want to merge the duplicate consecutive rows on columns <code>a</code> and <code>b</code> and then I want to update the <code>start_time</code> and <code>end_time</code> of the new row to be the earlier of the two and the later of the two, respectively.</p>
  
  <p>Because the entries are consecutive, this means keep the <code>start_time</code> of the first and <code>end_time</code> of second. Usually there are two duplicates one after another.</p>
  
  <p>So in the case above, I want to merge rows <code>1</code> and <code>2</code> and end up with:</p>
  
  <pre><code>     |a    |b    |start_time  |end_time
  0    |aaba    |d     |11:26       | 11:27
  1    |aba     |c     |11:27       | 11:34
  2    |cab     |ab    |11:34       | 11:35
  3    |aba     |c     |11:35       | 11:40
  </code></pre>
  
  <p>I tried using <code>loc</code> and on the first run to update the <code>end_time</code> column, and on second remove the duplicates, but it seems wasteful to run twice <code>loc</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>df.loc[(df['a']+df['b']) == (df['a']+df['b']).shift(-1), 'end_time'] = df['end_time'].shift(-1)
  
  df = df.loc[(df['a']+df['b']) != (df['a']+df['b']).shift(-1)]
  </code></pre>
  
  <p>Is there a way to remove the duplicates and update the <code>end_time</code> value only through one iteration?</p>