python - How to combine different cells according to the customer ID? -
this question has answer here:
- transform dataframe grouping row 3 answers
i have transaction data set , want transform according customer id. sample given below.
customerid description 17850 white hanging heart t-light holder 17850 white metal lantern 13047 assorted colour bird ornament 13047 poppy's playhouse bedroom 13047 poppy's playhouse kitchen
i want data set in following order:-
17850 white hanging heart t-light holder, white metal lantern 13047 assorted colour bird ornament,poppy's playhouse bedroom, poppy's playhouse kitchen
the dataset in csv format , each value in separate cell. can suggest method in excel or r or python?
you can use aggregate()
function, created own data, can own data frame above. based on customer
number, texts
concatenated
> df <- data.frame(customer = c(1,1,2,3,3,4), texts = c("aaa","aaa","bbb","bbb","ccc","ccc")) > df customer texts 1 1 aaa 2 1 aaa 3 2 bbb 4 3 bbb 5 3 ccc 6 4 ccc > aggregate(texts~customer,tostring,data=df) customer texts 1 1 aaa, aaa 2 2 bbb 3 3 bbb, ccc 4 4 ccc