0

I have the following dataframe where I wanted to combine products with the same value in Match column.

enter image description here

I did that by surfing and using the following piece of code

data2['Together'] = data2.groupby(by = ['Match'])['Product'].transform(lambda x : ','.join(x))
req = data2[['Order ID', 'Together']].drop_duplicates()
req

It gives the following result

enter image description here

Question 1
I tried to understand what was happening here by applying the same transform operation on each group and the transform function operates elementwise and gives something like this. So how does pandas change the result for the command shown above? enter image description here

Question 2
If I replace the transform with apply for the overall groupby then this gives weird results as shown below. Why does this happen? enter image description here

Dhruv
  • 17
  • 5
  • 1
    please provide all the code and data (input/output) as **text**, not images: [how to make reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – mozway May 04 '22 at 12:38

0 Answers0