我在数据框标签中有两个二进制变量:
target1=[0,1,0,0,0.....1]
target2=[1,1,0,0,0.....0]
我想创建第三个变量:
- 如果target1 = 0和target2 = 0,T = 0,
- 如果target1 = 1和target2 = 0,T = 1,
- 如果target1 = 0和target2 = 1,T = 2,
- 如果target1 = 1和target2 = 1,则T = 3。
for i in range(len(labels)):
if target1[i]==0 and target2[i]==0:
labels['T']=0
elif target1[i]==1 and target2[i]==0:
labels['T']=1
elif target1[i]==0 and target2[i]==1:
labels['T']=2
else:
labels['T']=3
由于某种原因,唯一的结果是0。我不确定出了什么问题。
答案 0 :(得分:0)
可能您需要更改
for i in range(len(labels)):
到
for i in range(len(target1)):
否则,您将只运行一次循环或标签中有项目的循环