i have a DF
User A B C
u1 1 0.3 5
u1 5 4 5
u1 6 1.3 2
U2 5 6.2 11
U2 1 7 6.5
the output that i want :
User combine
U1 [1,0.3 ,5,5 ,4, 5,6 ,1.3, 2]
U2 [5,6.2,11,1,7,6.5]
i tried :
DF['combine'] =DF.apply(lambda x: [x['A],x['B'],x['C']],axis=1)
User A B C combine
u1 1 0.3 5 [1,0.3,5]
u1 5 4 5 [5,4,5]
u1 6 1.3 2 [6,1.3,2]
U2 5 6.2 11 [5,6.5,11]
U2 1 7 6.5 [1,7,6.5]
and i group by user with join
DF.groupby(['user'])['combine'].agg(lambda x:','.join([str(x) for i in x])).to_frame()
User A B C combine
u1 1 0.3 5 [1,0.3,5] [5,4,5]....
U2 5 6.2 11 [5,6.5,11] [1,7,6.5]
the result was not accurate