How do I group max and min timestamp on pandas dataframe
问题 I want to group a dataset and return the maximum and minimum timestamp. Here's my data 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 Here's the output that i want 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 Here's what I did, the code seems not efficient, I hope theres better way to do this on pandas data1 = df.sort_values('timestamp').drop_duplicates(['customer_id']