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
  • 5,193
  • 4
  • 30
  • 59
Kirtash7
  • 25
  • 1
  • 6

2 Answers2

0

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

Arafat Khan
  • 777
  • 1
  • 10
  • 24
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
  • 5,193
  • 4
  • 30
  • 59