Python:决策树条件

用户29617

我正在尝试用 Python 编写决策树逻辑的一部分。数据来自数据帧 1 中的列表 1 和数据帧 2 中的列表 2 和列表 3。它指出:如果列表 2 和列表 3 中的项目都在列表 1 中的某处找到,并且列表 2 和列表 3 中的项目并排不是一样,然后打印出List 2 items。我不知道如何解决这个问题。嵌套 for 循环?或者是否有最好使用的功能。如果有人能指出我正确的方向。谢谢!

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

SlasherZer0

你的逻辑会沿着这条路走下去

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章