I have the following dataframe where I wanted to combine products with the same value in Match column.
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
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?
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?