df = pd.DataFrame({'a': randint(0, 60, 600), 'b': [1, 2, 5, 5, 4, 6] * 100})

def f(df):
    keys, values = df.sort_values('a').values.T
ukeys, index = np.unique(keys, True)
arrays = np.split(values, index[1:])
df2 = pd.DataFrame({'a': ukeys, 'b': [list(a) for a in arrays]})
return df2
grouping rows in list in pandas groupby