title: Create table of records from subsets of a dataframe in python using datetime column
body: <p>Be the following pandas DataFrame in Python:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>date</th>
  <th>direction</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>2022-01-03 10:00:01</td>
  <td>IN</td>
  </tr>
  <tr>
  <td>0</td>
  <td>2022-01-03 11:00:01</td>
  <td>IN</td>
  </tr>
  <tr>
  <td>0</td>
  <td>2022-01-03 11:10:01</td>
  <td>OUT</td>
  </tr>
  <tr>
  <td>0</td>
  <td>2022-01-03 12:00:03</td>
  <td>IN</td>
  </tr>
  <tr>
  <td>0</td>
  <td>2022-01-03 14:32:01</td>
  <td>OUT</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2022-01-03 10:32:01</td>
  <td>OUT</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2022-01-04 11:32:01</td>
  <td>IN</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2022-01-04 14:32:01</td>
  <td>OUT</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2022-01-02 08:00:01</td>
  <td>OUT</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2022-01-02 08:02:01</td>
  <td>IN</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I need to get the check-in and check-out for each group by ID. Considering that an <code>entry_date</code> is registered by direction = IN and an <code>exit_date</code> by direction = OUT. The idea is to create the record as follows:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>entry_date</th>
  <th>exit_date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>2022-01-03 10:00:01</td>
  <td>2022-01-03 11:10:01</td>
  </tr>
  <tr>
  <td>0</td>
  <td>2022-01-03 12:00:03</td>
  <td>2022-01-03 14:32:01</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2022-01-04 11:32:01</td>
  <td>2022-01-04 14:32:01</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>They are only recorded if a row with IN appears first and closes the record with a row with OUT as value for direction column (there may be more rows in between with a value of direction IN, as can be seen in the example).</p>
  <p>I hope you can help me, thank you in advance.</p>