How to find values from one dataframe in another using pandas?
<pre><code>I have two dataframes:

    df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],'B': ['B7', 'B4', 'B0', 'B3'] })
    df2 = pd.DataFrame({'A': ['A4', 'A3', 'A7', 'A8'],'B': ['B0', 'B1', 'B2', 'B3']})
</code></pre>

<p>and i need to get all the common values from the column <code>B</code>, so here it would be  <code>B0</code> and <code>B3</code>.</p>

<p>Using <code>df1.B.isin(df2.B)</code> gives me <code>False False True True</code>, but not a list of values. </p>

<p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>

<pre><code>print (df1[df1.B.isin(df2.B)])

    A   B
2  A2  B0
3  A3  B3

print (df1.ix[df1.B.isin(df2.B), 'B'])
2    B0
3    B3
Name: B, dtype: object

print (df1.ix[df1.B.isin(df2.B), 'B'].tolist())
['B0', 'B3']
</code></pre>

<p>Another solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>:</p>

<pre><code>print (pd.merge(df1,df2, on='B'))
  A_x   B A_y
0  A2  B0  A4
1  A3  B3  A8

print (pd.merge(df1,df2, on='B')['B'])
0    B0
1    B3
Name: B, dtype: object
</code></pre>

python pandas indexing merge condition