下面是我的pandas数据帧,每列包含0
或1
。如果其他列(severe_toxic
,…,identity hate
)中至少有一列包含1
,我正在尝试将现有的'toxic'
替换为1
我尝试了下面的代码,但它给出了错误
我试过的代码:
# a1 - above dataframe's name
a1['toxic'] = [1 if any(a1[[severe_toxic','obscene','threat','insult','identity_hate']]) ==1]
Tags:
使用Pandas而不是Python中的
any
:使用:
Input:
Output:
Setup:
相关问题 更多 >
编程相关推荐