如何从 python 中的字符串数组列表中删除停用词?

How do I remove stop words from an arraylist of strings in python?

我想从名为 arrayList1 的数组列表中删除停用词,该数组存储在数据变量中。 我尝试了以下方法,但它不起作用。请帮我检查下面的代码并改进codes.Thanks。

import Retrieve_ED_Notes
from nltk.corpus import stopwords

data = Retrieve_ED_Notes.arrayList1

stop_words = set(stopwords.words('english'))


def remove_stopwords(data):
 data = [word for word in data if word not in stop_words]
 return data

for i in range(0, len(remove_stopwords(data))):
  print(remove_stopwords(data[i]))

arrayList1 的控制台输出:

1|I really love writing journals
2|The mat is very comfortable and I will buy it again likes
3|The mousepad is smooth
1|I really love writing journals
4|This pen is very special to me.
4|This pencil is very special to me.
5|Meaningful novels
4|It brights up my day like a lighter and makes me higher.
6|School foolscap
7|As soft as my heart.lovey

将单词转换为较低的并使用停用词进行检查。

from nltk.corpus import stopwords
stopwords=set(stopwords.words('english'))

data =['I really love writing journals','The mat is very comfortable and I will buy it again likes','The mousepad is smooth']

def remove_stopwords(data):
    output_array=[]
    for sentence in data:
        temp_list=[]
        for word in sentence.split():
            if word.lower() not in stopwords:
                temp_list.append(word)
        output_array.append(' '.join(temp_list))
    return output_array





output=remove_stopwords(data)

print(output)
['really love writing journals','mat comfortable buy likes', 'mousepad smooth']