import pandas as pd
df = {'id':['a','a','b','c','c'],
'type':['red','blue','egg','star','cricle']}
df = pd.DataFrame(df)
grouped = df.groupby('id')
result = grouped['type'].unique()
result2 = result.reset_index()
result2
result2['type2'] = result2['type'].apply(lambda x: ';'.join(x))
result2
参考文章:
https://blog.csdn.net/sinat_34479648/article/details/92579070