Skip to content
Advertisement

How to merge two rows of a pandas dataframe depending on a condition in Python?

I have a dataframe :

JavaScript

Index 2 and 3 have the same product id’s, hence its the same order, so i am trying to combine the rows into one single row, to get :

JavaScript

the final df being :

JavaScript

I have tried using df.groupby function :

JavaScript

But it throws datatype error

JavaScript

Advertisement

Answer

JavaScript

The output is:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement