import pandas as pd
I have a Dataframe Table
d1 = pd.DataFrame({'ID_A':[1, 2, 3], 'name':['Micha', 'Micha', 'Lea']})
-----------------
- ID_A - name
-----------------
- 1 - Micha
- 2 - Micha
- 3 - Lea
-----------------
I wanna do a self join to get the following
---------------------------
- ID_A_x - name - ID_A_y -
---------------------------
- 1 - Micha - 1 -
- 1 - Micha - 2 -
- 3 - Lea - 3 -
---------------------------
But with
pd.merge(d1, d1, left_on='name', right_on='name', how='left')
i get duplicate pairs that are the same for me, how to avoid them? This result is not what i want:
---------------------------
- ID_A_x - name - ID_A_y -
---------------------------
- 1 - Micha - 1 -
- 1 - Micha - 2 -
- 2 - Micha - 2 -
- 2 - Micha - 1 -
- 3 - Lea - 3 -
---------------------------
Please help.
