Question: I want to fill missing values of a specific column only if a condition is met.

```
e.g. A    B
     Nan  0
     Nan  0
     0    0
     Nan  1
     Nan  1
     .....................
     .....................

```

In the above case I want to fill Nan values in column A only when corresponding value in column B is 0. Rest values in A (with Nan) should not change.

Answer: 
Use [`mask`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html) with [`fillna`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.fillna.html):

```
df['A'] = df['A'].mask(df['B'] == 0, df['A'].fillna(3))

```

Alternatives with [`loc`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html), [`numpy.where`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html):

```
df.loc[df['B'] == 0, 'A'] = df['A'].fillna(3)

df['A'] = np.where(df['B'] == 0, df['A'].fillna(3), df['A'])

```

---

```
print (df)
     A  B
0  3.0  0
1  3.0  0
2  0.0  0
3  NaN  1
4  NaN  1

```
You should use a loop over all elements, something like this:

```
for i in range(len(A))
   if numpy.isnan(A[i]) && B[i] == 0:
      A[i] = value

```

There are nicer ways to implement these loops, but I don't know what structures you are using.