赞
踩
1.直接放源代码
import xlrd from textblob import TextBlob import nltk import numpy as np import pandas as pd # 读入文件 from textblob.en import polarity inpath = 'E:\\Desktop\\Twitter.xlsx' List1 = {} data = xlrd.open_workbook(inpath, encoding_override='utf-8') table = data.sheets()[0] nrows = table.nrows ncols = table.ncols # 对每一条文本记录进行情感分析 for i in range(0, nrows): alldata = table.row_values(i) result = alldata[0] result = str(result) blob = TextBlob(result) List1[i] = blob.sentiment.polarity A = pd.Series(List1) print(A) A.to_excel('E:\\Desktop\\ouput.xlsx') a=b=c=0 for i in A: if i>0: a+=1 else: if i<0: b+=1 else: c+=1 print("positive:"+str(a),"negative:"+str(b),"neutral:"+str(c)) print(type(List1)) print(List1)
2.运行结
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。