python - Pandas, Fill Boolean Value compare two row -
my data
b 1 false true 2 false true 3 false true 4 false true 5 true false 6 true false 7 false true 8 true false 9 true true 10 false true 11 false true 12 false true 13 true false 14 true false 15 false false 16 false false 17 false false
my code
data.loc[(data['b']== false) & (data['b'].shift(1) == true), 'a'] = true data.loc[(data['a'].shift(1)== true) & (data['b'].shift(1) == false),'a'] = true
my desire result row no. 15,16,17 true,
b 1 false true 2 false true 3 false true 4 false true 5 true false 6 true false 7 false true 8 true false 9 true true 10 false true 11 false true 12 false true 13 true false 14 true false 15 **true** false 16 **true** false 17 **true** false
once 'a' "true" "true" before meet "b" "true" , "b" become "true" "a" turn "false"
is there simple solution solving this? in advance!!
Comments
Post a Comment