Replace pandas zero value with ffill non-zero, if the subsequent value is non-zero

Viewed 683

I need to replace "0" row data in pandas with the previous rows non-zero value IF and ONLY IF, the value in the row following the "0" is non zero.

I.e.

101
92
78
0
107
0
0

would become:

101
92
78
78
107
0
0

Any ideas how to do this would be much appreciated :-)

Thanks!

2 Answers
Related