0

I am trying to write part of my decision tree logic in Python. The data is coming from List 1 in dataframe 1 and List 2 and List 3 in dataframe 2. It states: if items in List 2 and List 3 are both found somewhere in List1 AND items in List 2 and List 3 side by side are NOT the same, then print out List 2 items. I am not sure how to approach this. Nested for loops? Or is there a function that would be best to use. If someone could point me in the right direction. Thanks!

for items 2 in list 2 AND for items 3 in list 3: for items 1 in list 1: if items 2 == items 1 AND if items 3 == items 1 AND if items 2 = [x for x, y in zip(list 2, list 3) if x != y]: then print items 2 in a list

user29617
  • 49
  • 5
  • Please read this to improve your question: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Be Chiller Too Jun 14 '21 at 14:53

1 Answers1

0

Your logic will go something along this way

list_1 = df1["List 1"].values  # List 1 from DataFrame1
list_2_and_3 = df2[["List 2", "List 3"]].values  # List 2 and 3 from DataFrame2

for element in list_2_and_3:
    # element[0] is from List 2
    # element[1] is from List 3
    if element[0] in list_1 and element[1] in list_1:  # if both are present in the list 1
        if element[0] != element[1]:  # If they are not the same
            print(element[0])  # print List 2 items