how to select group by in pandas code example Example: dataframe, groupby, select one df.sort_values('date').groupby(['id', 'period', 'type']).first()