【问题标题】:Importing stopword dictionary to python将停用词字典导入python
【发布时间】:2018-11-20 12:46:30
【问题描述】:

如何将特定的停用词词典(excel 表)导入 Python 并将其另外运行到 nltk 停用词列表中?目前我的停用词部分如下所示:

# filter out stop words
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
words = [w for w in words if not w in stop_words]

提前致谢!

【问题讨论】:

    标签: python nltk stop-words


    【解决方案1】:

    您可以使用 pandas 库导入 Excel 工作表。此示例假定您的停用词位于第一列,每行一个单词。然后,创建 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]
    

    【讨论】:

      猜你喜欢
      • 2016-01-23
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      相关资源
      最近更新 更多