From this data frame:
df =
ID TYPE VD_0 VD_1 VD_2 VD_3 VD_4 VD_5 Val_0 Val_1 Val_2 Val3 Val_4 Val_5
1 ABC V1234 aaa bbb 456 123 aaa 0 0 0 1 0 0
2 DBC 456 A45 aaa V1234 bbb 564 0 0 0 0 0 0
3 ABD V1234 V1234 bbb ccc 456 123 0 0 0 0 0 1
4 ABD ccc RTY SSW 123 ccc 123 0 0 0 0 1 0
I want to select only those column values VD_that are in this list:
myList = head + tail
Rule 1: In addition, the selected lines must begin with the following values:
head = ["V1234","RTY"]
Rule 2: and must have a corresponding Val_equal to 0 for the value immediately following headand belonging to tail:
tail = ["456","123"]
The result should be like this (for example, line ID1 is not included, since it has Val_31, which means that rule 2 is not executed):
result =
ID TYPE Col_1 Col_2 Col_3 Col_4 Val_1 Val_2 Val_3 Val_4
3 ABD V1234 V1234 456 123 0 0 0 1
4 ABD RTY 123 123 0 0 0
source
share