Subset pandas dataframe by overlap with another
<p>For the following two dataframes:</p>

<pre><code>df1 = pd.DataFrame({'name': pd.Series(["A", "B", "C"]), 'value': pd.Series([1., 2., 3.])})

     name  value
0    A    1.0
1    B    2.0
2    C    3.0

df2 = pd.DataFrame({'name': pd.Series(["A", "C", "D"]), 'value': pd.Series([1., 3., 5.])})

     name  value
0    A    1.0
1    C    3.0
2    D    5.0
</code></pre>

<p>I would like to keep only the rows in <code>df2</code> where the value in the <code>name</code> column overlaps with a value in the <code>name</code> column of <code>df1</code>, i.e. produce the following dataframe:</p>

<pre><code>     name  value
0    A    1.0
1    C    3.0
</code></pre>

<p>I have tried a number of approaches but I am new to python and pandas and don't appreciate the syntax coming from R. Why does this line of code not work, and what would?</p>

<pre><code>df2[df2["name"] in df1["name"]]
</code></pre>