df groupby take row code example
Example 1: pandas new df from groupby
df = pd.DataFrame(old_df.groupby(['groupby_attribute'])['mean_attribute'].mean())
df = df.reset_index()
df
Example 2: dataframe, groupby, select one
df.sort_values('date').groupby(['id', 'period', 'type']).first()