vlookup between 2 Pandas dataframes
<p>I have 2 pandas Dataframes as follows.</p>

<p>DF1:</p>

<pre><code>Security     ISIN
ABC           I1 
DEF           I2
JHK           I3
LMN           I4
OPQ           I5
</code></pre>

<p>and DF2:</p>

<pre><code>ISIN      Value
 I2        100
 I3        200
 I5        300
</code></pre>

<p>I would like to end up with a third dataframe looking like this:</p>

<p>DF3:</p>

<pre><code>Security   Value
 DEF       100
 JHK       200
 OPQ       300
</code></pre>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>pd.merge</code></a> to automatically do an inner join on <code>ISIN</code>. The following line of code should get you going:</p>

<pre><code>df3 = pd.merge(df1, df2)[['Security', 'Value']]
</code></pre>

<p>Which results in <code>df3</code>:</p>

<pre><code>  Security  Value
0      DEF    100
1      JHK    200
2      OPQ    300
</code></pre>

<p>The fully reproducible code sample looks like:</p>

<pre><code>import pandas as pd

df1 = pd.DataFrame({
        'Security': ['ABC', 'DEF', 'JHK', 'LMN', 'OPQ'],
        'ISIN' : ['I1', 'I2', 'I3', 'I4', 'I5']
    })
df2 = pd.DataFrame({
        'Value': [100, 200, 300],
        'ISIN' : ['I2', 'I3', 'I5']
    })

df3 = pd.merge(df1, df2)[['Security', 'Value']]
print(df3)
</code></pre>

python pandas