Problem with sort by and group by in pandas I have a DataFrame with duplicate id's but have different dates.

For Example:

A          B
1    12.09.2015
1    14.08.2018
1    13.07.2012
2    01.09.2015
2    09.10.2011


I want to group them by the Id's and get each of their maximum and minimum dates and create a different dataframe with each line for one id like:

A  B(min)  B(max)
All you need is a groupby operation + aggregation on the min/max values.


df.groupby('id').agg(('min','max'))['date_column']


The output should be like this : different dataframe with each line containing an id and the min/max dates.