我想使用Textblob执行情绪分析

2024-09-30 01:24:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经删除了stopwords,现在我想执行情绪分析,但我的代码显示了一个错误

导入字符串

从nltk.corpus导入停止词

ensw=stopwords.words('english')

从nltk.tokenize导入单词\u tokenize,发送\u tokenize

从textblob导入textblob

导入csv

打开('Huawei Japan Times.csv','r')作为csv\u文件:

csv_reader = csv.reader(csv_file)                                       

next(csv_reader)                                                        

for row in csv_reader:                                                  

    sentence = row[0]                                                   

    blob = TextBlob(sentence)                                           

    new_row = blob.lower()                                              

    token = TextBlob(sentence)                                          

    article_token = token.words                                         

    no_stop = [item for item in article_token if item not in ensw]      


    print(no_stop)                                                      

    print()                                                             

在这之后,我不知道如何进行情绪分析


Tags: csvintokenforitemsentencereaderrow

热门问题