Reputation: 45
I have the table below, where the missing values in columns Bird1 and Bird2 must be replaced by the result of the linear equation Y(X) = aX + b
, where "a" and "b" are constants.
Bird1 | Bird2 | Bird3 |
---|---|---|
22 | 33 | X0 |
NaN |
4 | X1 |
3 | NaN |
X2 |
1 | NaN |
X3 |
The result should be as per the table below. How to implement this code in python?
Bird1 | Bird2 | Bird3 |
---|---|---|
22 | 33 | X0 |
aX1+b |
4 | X1 |
3 | aX2+b |
X2 |
1 | aX3+b |
X3 |
Upvotes: 1
Views: 729
Reputation: 541
Here's a way to do it using pandas.DataFrame.fillna
# define a and b constants, ex.
a = 10
b = 5
df.Bird1.fillna(a*df.Bird3 + b, inplace=True)
df.Bird2.fillna(a*df.Bird3 + b, inplace=True)
Upvotes: 1