Edit: I am now looking for a clean way to impute the missing value of my dataset on Python
a b c
0 1 2 Falcon
1 np.nan 3 Falcon
2 np.nan np.nan Falcon
3 np.nan 4 Bird
4 np.nan 5 Bird
5 5 np.nan Bird
6 6 7 Bird
I will need to impute using the following conditions based on their individual group.
(1) for missing values that has a value in its preceding and previous row, fill it by interpolating
(2) for missing values that has a value in its preceding or previous row, fill it with the preceding or previous row value
(3) for missing values that does not satisfy (1) and (2), fill it with 0
An example of the result will be
a b c
0 1 2 Falcon
1 1 3 Falcon
2 0 3 Falcon
3 0 4 Bird
4 5 5 Bird
5 5 6 Bird
6 6 7 Bird
I have tried the code provided in the comment below, however i failed to set it via its respective group. How do I go about doing it in Python?