DataFrame中的apply函数:将函数应用到由列或行形成的一维数组上。
示例,根据新增一列,其列值根据另外两列的值计算得到。
#打标签
def target(a,b,c):
if a==1 or (b==1 and c>=0.5):
return 1
else:
return 0
dfTest['target'] = dfTest.apply(lambda x: target(x.question_click, x.appear,x.score), axis = 1)