Вы можете импортировать лист Excel, используя библиотеку pandas
.В этом примере предполагается, что ваши стоп-слова расположены в первом столбце, по одному слову в строке.Затем создайте объединение nltk
стоп-слов и ваших собственных стоп-слов:
import pandas as pd
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
# check pandas docs for more info on usage of read_excel
custom_words = pd.read_excel('your_file.xlsx', header=None, names=['mywords'])
# union of two sets
stop_words = stop_words | set(custom_words['mywords'])
words = [w for w in words if not w in stop_words]