Fill missing values of 1 data frame from another data frame using pandas
<p>Need help in filling 0's.</p>

<p>In the below dataframe i have a column "Item_Visibility" which has zeros. I need to fill those with values from second dataframe(image 2). The common column between the 2 dataframes is "Item_Identifier".</p>

<p>Thanks in advance</p>

<p><a href="http://i.stack.imgur.com/XnvfR.png" rel="nofollow"><img src="http://i.stack.imgur.com/XnvfR.png" alt="enter image description here"></a>
<a href="http://i.stack.imgur.com/muRHU.png" rel="nofollow"><img src="http://i.stack.imgur.com/muRHU.png" alt="enter image description here"></a></p>

<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html" rel="nofollow"><code>mask</code></a> with maping by <code>Series</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a>:</p>

<pre><code>print (df1)
       a      b        c      d
0  FDA15   9.30  Low Fat  0.016
1  FDX07  19.20  Regular  0.000
2  NCD19   8.93  Low Fat  0.000
3  FDP10    NaN  Low Fat  0.127

print (df2)
       e       d
0  FDW59  0.0202
1  FDX07  0.0178

df1.d = df1.d.mask(df1.d == 0, df1.a.map(df2.set_index('e')['d']))
print (df1)
       a      b        c       d
0  FDA15   9.30  Low Fat  0.0160
1  FDX07  19.20  Regular  0.0178
2  NCD19   8.93  Low Fat     NaN
3  FDP10    NaN  Low Fat  0.1270
</code></pre>

python pandas