Хорошо, давайте предположим, что у нас есть фрейм данных data
и список negative_words
примерно так:
data = pd.DataFrame({
'Tweets' : ['This is bad', 'This is terrible', 'This is good', 'This is great'],
})
negative_words = ['bad', 'terrible']
Затем мы можем сделать что-то вроде:
1) Мы можем использовать lambda
функция с any
:
# create lambda with any:
data['Negative'] = data.apply(lambda x: True if any(word in x.Tweets for word in negative_words) else False, axis=1)
И получит:
Tweets Negative
0 This is bad True
1 This is terrible True
2 This is good False
3 This is great False