Mapping data from other dataset. Python Pandas
<p>So i got 2 datasets, <code>df1</code> has the colour for all fruits and <code>df2</code> don't. How do I map the color values for <code>df2</code> based on the color data from <code>d1</code>, according to the fruit names? </p>

<pre><code>               df1                                  df2
Name               Color             Name              Color
Apple              Red               Orange            Na
Orange             Orange            Coconut           Na
Pear               Pear              Pear              Na
Pear               Pear              Strawberries      Na
Papaya             Papaya            Banana            Na
Watermelon         Watermelon        Papaya            Na
               "                  "                 "                 "
</code></pre>

<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a>, but first need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.drop_duplicates.html" rel="nofollow"><code>Series.drop_duplicates</code></a>:</p>

<pre><code>df2['Color'] = df2['Name'].map(df1.set_index('Name')['Color'].drop_duplicates())
print (df2)
           Name   Color
0        Orange  Orange
1       Coconut     NaN
2          Pear    Pear
3  Strawberries     NaN
4        Banana     NaN
5        Papaya  Papaya
</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> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html" rel="nofollow"><code>DataFrame.drop_duplicates</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html" rel="nofollow"><code>DataFrame.drop</code></a>:</p>

<pre><code>df2 = pd.merge(df2.drop('Color', axis=1),df1.drop_duplicates(), how='left')
print (df2)
           Name   Color
0        Orange  Orange
1       Coconut     NaN
2          Pear    Pear
3  Strawberries     NaN
4        Banana     NaN
5        Papaya  Papaya
</code></pre>

python pandas merge mapping multiple-columns