title: Create new column in Pandas dataframe based on latest value per ID
body: <p>I have <code>df</code> below which I have sorted according to the <code>ID</code>variable and the time variable <code>T</code> as the secondary sort.</p>
  
  <pre><code>df = pd.DataFrame({
      'ID': ['a', 'b', 'c', 'b', 'b'],
      'T': [
          datetime.datetime(2019, 1, 1),
          datetime.datetime(2017, 1, 1),
          datetime.datetime(2018, 1, 1),
          datetime.datetime(2020, 1, 1),
          datetime.datetime(2021, 1, 1)],
      'V': [3, 5, 8, 6, 1]
  }).sort_values(['ID', 'T'], ascending=False)
  
  df
  
      ID  T           V
  2   c   2018-01-01  8
  4   b   2021-01-01  1
  3   b   2020-01-01  6
  1   b   2017-01-01  5
  0   a   2019-01-01  3
  </code></pre>
  
  <p>I want to add a new column <code>V_L</code> where, for each <code>ID</code>, the last value (based on the time column <code>T</code>) is shown. If there is no last value this should be indicated by a <code>null</code> value in <code>V_L</code>. An example output would look like this:</p>
  
  <pre><code>df
      ID  T           V   V_L
  0   a   2018-01-01  8   NaN
  1   b   2021-01-01  1   6.0
  2   b   2020-01-01  6   5.0
  3   b   2017-01-01  5   NaN
  4   c   2019-01-01  3   NaN
  </code></pre>