だから私はストップワードを使用から削除したいデータセットを持っています
stopwords.words('english')
コード内でこれを使用して、これらの単語を単に取り出す方法に苦労しています。私はすでにこのデータセットの単語のリストを持っています。私が苦労している部分は、このリストと比較してストップワードを削除することです。どんな助けでも大歓迎です。
だから私はストップワードを使用から削除したいデータセットを持っています
stopwords.words('english')
コード内でこれを使用して、これらの単語を単に取り出す方法に苦労しています。私はすでにこのデータセットの単語のリストを持っています。私が苦労している部分は、このリストと比較してストップワードを削除することです。どんな助けでも大歓迎です。
from nltk.corpus import stopwords
# ...
filtered_words = [word for word in word_list if word not in stopwords.words('english')]
ストップワードを削除したい単語のリスト (word_list) があるとします。次のようなことができます。
filtered_word_list = word_list[:] #make a copy of the word_list
for word in word_list: # iterate over word_list
if word in stopwords.words('english'):
filtered_word_list.remove(word) # remove word from filtered_word_list if it is a stopword
データが として保存されている場合、デフォルトで NLTK ストップワード リストを使用する from textero を使用Pandas DataFrame
できます。remove_stopwords
import pandas as pd
import texthero as hero
df['text_without_stopwords'] = hero.remove_stopwords(df['text'])