'Transform gives different results when applied on individual groups rather than specifying after groupby

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source