Python 文本清理问题

Python 文本清理问题,python,text,nlp,topic-modeling,Python,Text,Nlp,Topic Modeling,我正在学习使用python在线清理文本。 我已经去掉了一些停止词,把字母放低了 但是当我执行这段代码时,它没有显示任何内容 我不知道为什么 # we add some words to the stop word list texts, article = [], [] for w in doc: # if it's not a stop word or punctuation mark, add it to our article! if w.text != '\n' and

我正在学习使用python在线清理文本。 我已经去掉了一些停止词,把字母放低了

但是当我执行这段代码时,它没有显示任何内容

我不知道为什么

# we add some words to the stop word list
texts, article = [], []
for w in doc:
    # if it's not a stop word or punctuation mark, add it to our article!
    if w.text != '\n' and not w.is_stop and not w.is_punct and not w.like_num and w.text != 'I':
        # we add the lematized version of the word
        article.append(w.lemma_)
    # if it's a new line, it means we're onto our next document
    if w.text == '\n':
        texts.append(article)
        article = []

当我试图输出文本时,它只是空白。

我相信“文本”列表和“文章”列表指的是相同的内容,因此,清除一个列表的内容也会清除另一个列表

下面是一个类似问题的链接:


请查看以上内容是否有用。

什么是文档?它是如何定义和初始化的?Doc是一个普通的txt文件。如何打开该文件并从中读取?你能给我看看那部分吗?另外,最好在for循环的开头放一个
print(w)
,看看w是否有值text=open(“BioTest.txt”)。read()我试着打印w,它有值