1

I have this dataset:

DF1

| ID    | artshort  | artlong  |
| 248   | 123       |          |
| 249   | 456-1     |          |
| 100   | 456       | 456-1    |

As a result I want a dataset with the rows where artshort of one row is the same as artlong of another row.

I tried:

dftest = df1['artshort'].isin(df1['artlong'])]

But this is not working. Not sure if "isin" is the best approach in this case

hacking_mike
  • 1,005
  • 1
  • 8
  • 22

1 Answers1

1

You can try filtering using this condition:

data = {'ID': [248, 249, 100],
        'artshort': ['123', '456-1', '456'],
        'artlong': ['', '', '456-1']}

df1 = pd.DataFrame(data)

result = df1[df1['artshort'].isin(df1['artlong'])]

Output:

    ID  artshort    artlong
1   249 456-1   
Guru Stron
  • 102,774
  • 10
  • 95
  • 132