Intergrating 2 dataframes based on specific column values
<p>I am not sure if my question is correct or not, but I will try to explain it clearly here.</p>

<p>I have two dataframes, df and df2.</p>

<p>df consist of country names and their short names</p>

<pre><code> Country    |    Shortname
 England           ENG
 United States     USA
 China             CN
 Thailand          TH
</code></pre>

<p>df2 consists of multiple country names including duplicates:</p>

<pre><code>Country
England
England
China
China
China
Thailand
England
</code></pre>

<p>I want to integrate Shortname from df in to a new column Shortname in df2 by comparing Country in both dataframes.
This is my desired result:</p>

<p>df2</p>

<pre><code>Country   |   Shortname
England         ENG
England         ENG
China           CN
China           CN
China           CN
Thailand        TH
England         ENG
</code></pre>

<p>Thank you very much.</p>

<p>I'd use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow">map()</a> method in this case:</p>

<pre><code>In [49]: df
Out[49]:
         Country Shortname
0        England       ENG
1  United States       USA
2          China        CN
3       Thailand        TH

In [50]: df2
Out[50]:
    Country
0   England
1   England
2     China
3     China
4     China
5  Thailand
6   England

In [52]: df2['Shortname'] = df2.Country.map(df.set_index('Country').Shortname)

In [53]: df2
Out[53]:
    Country Shortname
0   England       ENG
1   England       ENG
2     China        CN
3     China        CN
4     China        CN
5  Thailand        TH
6   England       ENG
</code></pre>

python pandas dataframe