I have a dataframe df with the columns X . I would like to create a new column Y out of X
Y should be 1 if X in the same row is 1 and the 0´s (also in X) above should be minimum a count of n (variable). If the zeros above less than n, the result should be "" Y. I tried (hours) np.where, without success. I think I need a lambda-function, but have no idea how to start or research.
Exampel n = 4:
On date 2018-01-25, result is 1 because X is 1 and the 0´s above are more than 4.
On Date 2018-01-25, result is "" because 0´s above just 3 (not 4)
Dates X Y (like it should be...)
2018-01-02 0
2018-01-03 0
2018-01-04 0
2018-01-05 0
2018-01-08 0
2018-01-09 0
2018-01-10 0
2018-01-11 0
2018-01-12 0
2018-01-15 0
2018-01-16 0
2018-01-17 0
2018-01-18 0
2018-01-19 0
2018-01-22 0
2018-01-23 0
2018-01-24 0
2018-01-25 1 1
2018-01-29 0
2018-01-30 0
2018-01-31 0
2018-02-02 1
2018-02-05 0
2018-02-06 0
2018-02-07 0
2018-02-08 0
2018-02-09 1 1
2018-02-12 1
2018-02-13 0
Signal_Fis 1 you want to add a new column whereSignal_X = 1but only if the four rows above are0? so IIUC,2018-02-01will have1inSignal_X?