Groupby function edited