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