I have dataframe with time series where one column has strings: Normal Value and Wrong Value. I would like to find all rows which are just between rows with Wrong Value and assign them 0 to new column. Rows which have Normal Value and are not between rows with Wrong Value should have value 1. Value column represents high peaks in time series.
Sample dataframe:
>>> df = pd.DataFrame({'Date': ['2019-01-01','2019-01-02','2019-01-03','2019-01-04','2019-01-05','2019-01-06','2019-01-07','2019-01-08','2019-01-09', '2019-01-10'],
... 'Value': [-0.011295, -0.013431, 580944.426061, 0.000000, 0.000000, -0.999998, 0.000000, 0.000000, 712327.147257, -0.999999],
... 'String': ['Normal Value', 'Normal Value', 'Wrong Value', 'Normal Value', 'Normal Value', 'Wrong Value', 'Normal Value', 'Normal Value', 'Wrong Value', 'Wrong Value']})
>>> df
Date Value String
0 2019-01-01 -0.011295 Normal Value
1 2019-01-02 -0.013431 Normal Value
2 2019-01-03 580944.426061 Wrong Value
3 2019-01-04 0.000000 Normal Value
4 2019-01-05 0.000000 Normal Value
5 2019-01-06 -0.999998 Wrong Value
6 2019-01-07 0.000000 Normal Value
7 2019-01-08 0.000000 Normal Value
8 2019-01-09 712327.147257 Wrong Value
9 2019-01-10 -0.999999 Wrong Value
Expected output:
>>> df = pd.DataFrame({'Date': ['2019-01-01','2019-01-02','2019-01-03','2019-01-04','2019-01-05','2019-01-06','2019-01-07','2019-01-08','2019-01-09', '2019-01-10'],
... 'Value': [-0.011295, -0.013431, 580944.426061, 0.000000, 0.000000, -0.999998, 0.000000, 0.000000, 712327.147257, -0.999999],
... 'String': ['Normal Value', 'Normal Value', 'Wrong Value', 'Normal Value', 'Normal Value', 'Wrong Value', 'Normal Value', 'Normal Value', 'Wrong Value', 'Wrong Value'],
... 'Expected Value': [1, 1, 0, 0, 0, 0, 1, 1, 0, 0]})
>>> df
Date Value String Expected Value
0 2019-01-01 -0.011295 Normal Value 1
1 2019-01-02 -0.013431 Normal Value 1
2 2019-01-03 580944.426061 Wrong Value 0
3 2019-01-04 0.000000 Normal Value 0
4 2019-01-05 0.000000 Normal Value 0
5 2019-01-06 -0.999998 Wrong Value 0
6 2019-01-07 0.000000 Normal Value 1
7 2019-01-08 0.000000 Normal Value 1
8 2019-01-09 712327.147257 Wrong Value 0
9 2019-01-10 -0.999999 Wrong Value 0