I have the following df:
col1 col2 col3
0 a 1.0 1.0
1 b NaN NaN
2 c 5.0 3.0
3 d 5.0 NaN
I want to do forward fill the rows only where col2 = NaN so the result would be like this
col1 col2 col3
0 a 1.0 1.0
1 b 1.0 1.0
2 c 5.0 3.0
3 d 5.0 NaN
I was able to get to here but this isn't a smart solution because it ffills row 3 even though it doesn't meet the requirements of col2 = NaN
df['col2'] = df['col2'].fillna(method="ffill")
df['col3'] = df['col3'].fillna(method="ffill")
Code
output:
Example