df = df.groupby('l_customer_id_i').agg(lambda x: ','.join(x)) for name in df.index: print name print df.loc[name]