I have the dataframe as below:
df
ID val
1 0.0
2 yes
3 1.0
4 0.0
5 yes
How do I match my previous value with my current value if the column val equals "yes"
I tried using the code below:
df['val'] = df['val'].replace('yes', np.nan).bfill().astype(str)
I am getting this output which is not what I wanted to.
ID val
1 yes
2 yes
3 1.0
4 yes
5 yes
can we use np.where along with the bfill?