'How to append duplicate rows as columns in pandas?

I am trying to append the duplicated rows in one column. Duplication is based on some columns that need to be an exact match for a row to declare as a match. the problem is we can't say how many repeated rows will be there so the solution needs to be generic.

I have tried some other solution but they are based on some user_id or key column. In my case, all columns except one have to be compared exactly. and appended columns should have the same column name.

I used following code to find duplicated rows:

col = ['TITLE', 'ISSN', 'e-ISSN', 'ISBN', 'e-ISBN']
duplicated_data = data[data.duplicated(col, keep=False)]

Now I don't know what to do next

Here is a sample input output

input data:

------------------------------
DealName | Target | Category |
-----------------------------
ABC-XYZ  | ABC    | A        |
------------------------------
ABC-XYZ  | ABC    | B        |
------------------------------
ABC-XYZ  | None   | C        |

output data:

------------------------------------------------------------------------------------------
DealName | Target | Category |DealName | Target | Category 
---------------------------------------------------------------------------------------
ABC-XYZ  | ABC    | A        |ABC-XYZ  | ABC    | B        


Suppose I have set the condition that the first two columns need to be matched in order to select the row since 3rd row does not have the same value in the second column we ignored it.



Sources

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

Source: Stack Overflow

Solution Source