0

I started learning python recently and I need your help. I have a dataframe with the following structure

Dataframe

I need to make a transformation, all values ​​in column 2 (product id) that have the same order_id (column 1) must become a row and the values ​​must be separated by commas.

Like this: After transformation

How can I make this transformation? Can somebody help me?

Thanks !

Gangula
  • 3,484
  • 2
  • 19
  • 41
Kirtash7
  • 29
  • 1
  • 5

2 Answers2

0

You might want to refer to this question which is basically what you are asking for.

Arafat Khan
  • 618
  • 1
  • 6
  • 22
0

You can get your desired result using the following code

df.groupby(['order_id'])['product_id'].apply(','.join).reset_index()

You can refer to the following answer for more applications: https://stackoverflow.com/a/27298308/6908282

Gangula
  • 3,484
  • 2
  • 19
  • 41