【发布时间】:2020-05-05 20:45:11
【问题描述】:
df1:
stu_Id sub1 sub2 sub3
0 1001 45 68 69
1 1002 67 78 57
2 1003 76 68 78
3 1004 87 56 69
4 1005 45 43 73
df2 :
stu_Id sub1 sub2 sub3
0 1001 45 68 69
1 1002 45 68 69
2 1003 45 68 69
3 1004 45 68 69
4 1005 45 68 69
cond1= df1.to_numpy[:,[1]]>df2.to_numpy[:,[1]] then 1 else 0
cond2= df1.to_numpy[:,[2]]<df2.to_numpy[:,[2]] then 1 else 0
cond3= df1.to_numpy[:,[3]]-df2.to_numpy[:,[3]]>5 then 1 else 0
如何在 df1 中一次在列级别(sub1,sub2,sub3)上应用上述三个数组条件。 我试过了
df1['sub1','sub2','sub3']=
np.select[[cond1,cond2,cond3],.
[1,2,3],0]
这给了我错误。
输出:
stu_Id sub1 sub2 sub3
0 1001 0 0 0
1 1002 1 0 0
2 1003 1 0 1
3 1004 1 1 0
4 1005 0 1 0
【问题讨论】:
标签: python python-3.x pandas python-2.7 dataframe