title: How do I group max and min timestamp on pandas dataframe
body: <p>I want to group a dataset and return the maximum and minimum timestamp. Here's my data</p>
  
  <pre><code>id  timestamp
  1   2017-09-17 10:09:01
  2   2017-10-02 01:13:15
  1   2017-09-17 10:53:07
  1   2017-09-17 10:52:18
  2   2017-09-12 21:59:40
  </code></pre>
  
  <p>Here's the output that i want</p>
  
  <pre><code>id    max                   min
  1     2017-09-17 10:53:07   2017-09-17 10:09:01
  2     2017-10-02 01:13:15   2017-09-12 21:59:40
  </code></pre>
  
  <p>Here's what I did, the code seems not efficient, I hope theres better way to do this on pandas</p>
  
  <pre><code>data1 = df.sort_values('timestamp').drop_duplicates(['customer_id'], keep='last')
  data2 = df.sort_values('timestamp').drop_duplicates(['customer_id'], keep='first')
  data1['max'] = data1['timestamp']
  data2['min'] = data2['timestamp']
  data = data1.merge(data2, on = 'customer_id', how='left')
  data = data.drop(['timestamp_x','timestamp_y'], axis=1)
  </code></pre>
  
  <p>It seems that pandas have this type of pivot</p>