I have a df with two columns and I need to find and store only duplicates.
|-------------------|-------------|
| col1 | col2 |
|-------------------|-------------|
| apple | mango |
|-------------------|-------------|
| banana | grape |
|-------------------|-------------|
| pear | watermelon |
|-------------------|-------------|
| cherry | banana |
|-------------------|-------------|
| mango | apple |
|-------------------|-------------|
The result should return a df with col1 like this
|----------------|
| col1 |
|----------------|
| apple |
|----------------|
| banana |
|----------------|
| mango |
|----------------|
I tried something like this, but it doesnt fetch me the same resuts.
df['a_flag'] = df['col2'].isin(df['col1']).astype(int)
df1=df[(df['a_flag']==1)]