title: Get only the first and last rows of each group with pandas
body: <p>Iam newbie in python. I have huge a <code>dataframe</code> with millions of rows and id. my data looks like this:</p>
  
  <pre><code>Time    ID  X   Y
  8:00    A   23  100
  9:00    B   24  110
  10:00   B   25  120
  11:00   C   26  130
  12:00   C   27  140
  13:00   A   28  150
  14:00   A   29  160
  15:00   D   30  170
  16:00   C   31  180
  17:00   B   32  190
  18:00   A   33  200
  19:00   C   34  210
  20:00   A   35  220
  21:00   B   36  230
  22:00   C   37  240
  23:00   B   38  250
  </code></pre>
  
  <p>I want to sort the data on id and time. The expected result what I looking for like this"</p>
  
  <pre><code>Time    ID  X   Y
  8:00    A   23  100
  13:00   A   28  150
  14:00   A   29  160
  18:00   A   33  200
  20:00   A   35  220
  9:00    B   24  110
  10:00   B   25  120
  17:00   B   32  190
  21:00   B   36  230
  23:00   B   38  250
  11:00   C   26  130
  12:00   C   27  140
  16:00   C   31  180
  19:00   C   34  210
  22:00   C   37  240
  15:00   D   30  170
  </code></pre>
  
  <p>and I want to pick only "The first and the last" of the id and eliminate the rest. The expected result looks like this:</p>
  
  <pre><code>Time    ID  X   Y
  8:00    A   23  100
  20:00   A   35  220
  9:00    B   24  110
  23:00   B   38  250
  11:00   C   26  130
  22:00   C   37  240
  15:00   D   30  170
  </code></pre>
  
  <p>how to do it in pandas? thank you for your advice</p>