I have this pandas data frame:
df = DataFrame({'id':['a','b','b','b','c','c'], 'category':['z','z','x','y','y','y'], 'category2':['1','2','2','2','1','2']})
which looks like:
category category2 id
0 z 1 a
1 z 2 b
2 x 2 b
3 y 2 b
4 y 1 c
5 y 2 c
What i'd like to do is to groupby id and return the other two columns as a concatenation of unique strings.
The outcome would look like:
category category2 id
0 z 1 a
1 zxy 2 b
2 y 12 c
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…