mystery man
mystery man

Reputation: 437

Intersection of values in a common column of two dataframes- Pandas, Python3

I have 2 dataframes; dataframe main and dataframe mini, with exactly the same headers but with different values in them however there is some overlap. How would I get the duplicate values within a single column (e.g. Column 'Name').

Example:

dataframe main

Name    size    length
foo      1         2
foo2     3         4
foo3     5         6  
foo4     7         8

dataframe mini

Name     size     length
foox      60       70
foo3       3        4
fooy      50       60
foo4      7        8

psuedo code: intersect(column='Name', of='dataframe mini', against='dataframe main')

proposed out : (foo3,foo4)

Upvotes: 1

Views: 1123

Answers (1)

EdChum
EdChum

Reputation: 394031

You can use isin to mask the row values that are in another df:

In [52]:
main.loc[main['Name'].isin(mini['Name']), 'Name']

Out[52]:
2    foo3
3    foo4
Name: Name, dtype: object

Upvotes: 1

Related Questions