Skip to content
Advertisement

How to add rows with identical items in different columns in Pandas together

I have a sample dataframe that looks like below. I’d like to eventually group row 1 and row 3 together, since they contain identical items in different columns.

JavaScript

I’ve spent a lot of time trying to solve this, but have not encountered a good solution yet. What steps should I take to reach the below final dataframe?

JavaScript

Advertisement

Answer

You can try:

JavaScript

OUTPUT:

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