Is it possible to grab a given value in a Pandas column and change it to a previous row value?
For instance, I have this Dataframe:
Date Price Signal
2018-01-01 13380.00 1
2018-01-02 14675.11 0
2018-01-03 14919.51 0
2018-01-04 15059.54 0
2018-01-05 16960.39 0
2018-01-06 17069.79 -1
2018-01-07 16150.03 0
2018-01-08 14902.54 0
2018-01-09 14400.00 1
2018-01-10 14907.09 0
2018-01-11 13238.78 0
2018-01-12 13740.01 -1
2018-01-13 14210.00 0
I would like to replace the zeros in the Signal column for either 1 or -1. The final DF should be this:
Date Price Signal
2018-01-01 13380.00 1
2018-01-02 14675.11 1
2018-01-03 14919.51 1
2018-01-04 15059.54 1
2018-01-05 16960.39 1
2018-01-06 17069.79 -1
2018-01-07 16150.03 -1
2018-01-08 14902.54 -1
2018-01-09 14400.00 1
2018-01-10 14907.09 1
2018-01-11 13238.78 1
2018-01-12 13740.01 -1
2018-01-13 14210.00 -1