如何根据函数的返回值在python中设置新列?

时间:2019-08-12 10:19:27

标签: python-3.x

我正在用python进行一些文本挖掘,并且想要设置一个新列,如果我的搜索函数的返回值为true,则值为1;否则,则返回0。

我尝试了各种if语句,但是什么都无法工作。

下面是我正在做的简化版本:

<ComboBox x:Name="tab_combobox" ItemsSource="{Binding Tabs}" DisplayMemberPath="Title" Tag="{Binding Channel}" SelectedIndex="0"/>


<ComboBox x:Name="tab_channel_combobox"
ItemsSource="{Binding Source={x:Static model:Connection.Ports}}"
SelectedValue="{Binding SelectedItem.Tag, ElementName=tab_combobox}"
SelectedValuePath="Tag"
/>

1 个答案:

答案 0 :(得分:1)

这就是我想要的:

df['New'] = df['answer'].isin(words)*1

这个对我有用:

for i in range(0, len(df)):
    if set(words) <= set(df.text[i]):
        df['NEW'][i] = 1
    else:
        df['NEW'][i] = 0

如果使用此方法,则不需要此功能。