How to fill missing value based on other columns in Pandas dataframe? Suppose I have a 5*3 data frame in which third column contains missing value

1 2 3
4 5 NaN
7 8 9
3 2 NaN
5 6 NaN


I hope to generate value for missing value based rule that first product second column 

1 2 3
4 5 20 &lt;--4*5
7 8 9
3 2 6 &lt;-- 3*2
5 6 30 &lt;-- 5*6


How can I do it use data frame? Thanks.

How to add condition to calculate missing value like this?

if 1st % 2 == 0 then 3rd = 1st * 2nd
else 3rd = 1st + 2nd

1 2 3
4 5 20 &lt;-- 4*5 because 4%2==0
7 8 9
3 2 5 &lt;-- 3+2 because 3%2==1
5 6 11 &lt;-- 5+6 because 5%2==1
Assuming three columns of your dataframe is a, b and c. This is what you want:

df['c'] = df.apply(
    lambda row: row['a']*row['b'] if np.isnan(row['c']) else row['c'],
    axis=1
)


Full code:

df = pd.DataFrame(
    np.array([[1, 2, 3], [4, 5, np.nan], [7, 8, 9], [3, 2, np.nan], [5, 6, np.nan]]), 
    columns=['a', 'b', 'c']
)
df['c'] = df.apply(
    lambda row: row['a']*row['b'] if np.isnan(row['c']) else row['c'],
    axis=1
)