**
对excel文件中的英文文本内容进行情感分析
**
#导入库
import xlrd
from textblob import TextBlob
import nltk
import numpy as np
import pandas as pd
#读入文件
inpath = ‘input.xlsx’
List1 = {}
List2 = {}
data = xlrd.open_workbook(inpath,encoding_override = ‘utf-8’)
table = data.sheets()[0]
nrows = table.nrows
ncols = table.ncols
#对每一条文本记录进行情感分析
for i in range(1,nrows):
alldata = table.row_values(i)
result = alldata[0]
result = str(result)
blob = TextBlob(result)
List1[i-1] = blob.sentiment.polarity
List2[i-1] = blob.sentiment.subjectivity
#print(blob.sentiment)
#print(result)
#以excel形式保存结果
A = pd.Series(List1)
B = pd.Series(List2)
dataF = pd.DataFrame({‘polarity’:A,‘subjectivity’:B})
dataF.to_excel(“output.xlsx”)