title: Manipulate pandas columns with datetime
body: <p>Please see this SO post <a href="https://stackoverflow.com/questions/56431911/manipulating-pandas-columns">Manipulating pandas columns</a> </p>
  
  <p>I shared this dataframe:</p>
  
  <pre><code>+----------+------------+-------+-----+------+
  | Location |    Date    | Event | Key | Time |
  +----------+------------+-------+-----+------+
  | i2       | 2019-03-02 |     1 | a   |      |
  | i2       | 2019-03-02 |     1 | a   |      |
  | i2       | 2019-03-02 |     1 | a   |      |
  | i2       | 2019-03-04 |     1 | a   |    2 |
  | i2       | 2019-03-15 |     2 | b   |    0 |
  | i9       | 2019-02-22 |     2 | c   |    0 |
  | i9       | 2019-03-10 |     3 | d   |      |
  | i9       | 2019-03-10 |     3 | d   |    0 |
  | s8       | 2019-04-22 |     1 | e   |      |
  | s8       | 2019-04-25 |     1 | e   |      |
  | s8       | 2019-04-28 |     1 | e   |    6 |
  | t14      | 2019-05-13 |     3 | f   |      |
  +----------+------------+-------+-----+------+
  </code></pre>
  
  <p>This is a follow-up question. Consider two more columns after Date as shown below. </p>
  
  <pre><code>+-----------------------+----------------------+
  | Start Time (hh:mm:ss) | Stop Time (hh:mm:ss) |
  +-----------------------+----------------------+
  | 13:24:38              | 14:17:39             |
  | 03:48:36              | 04:17:20             |
  | 04:55:05              | 05:23:48             |
  | 08:44:34              | 09:13:15             |
  | 19:21:05              | 20:18:57             |
  | 21:05:06              | 22:01:50             |
  | 14:24:43              | 14:59:37             |
  | 07:57:32              | 09:46:21 
  | 19:21:05              | 20:18:57             |
  | 21:05:06              | 22:01:50             |
  | 14:24:43              | 14:59:37             |
  | 07:57:32              | 09:46:21             |
  +-----------------------+----------------------+
  </code></pre>
  
  <p>The task remains the same - to get the time difference but in hours, corresponding to the Stop Time of the first row and Start Time of the last row 
  for each Key. </p>
  
  <p>Based on the answer, I was trying something like this: </p>
  
  <pre><code>df['Time']=df.groupby(['Location','Event']).Date.\
             transform(lambda x : (x.iloc[-1]-x.iloc[0]))[~df.duplicated(['Location','Event'],keep='last')]
  
  df['Time_h']=df.groupby(['Location','Event'])['Start Time (hh:mm:ss)','Stop Time (hh:mm:ss)'].\
              transform(lambda x,y : (x.iloc[-1]-y.iloc[0]))[~df.duplicated(['Location','Event'],keep='last')]    # This gives an error on transform 
  </code></pre>
  
  <p>to get the difference in days and hours separately and then combine. Is there a better way? </p>