如何运用Python解决实际问题上,读文件然后能进行相应分析是很重要。
在这次事例中,用使用jieba库中的lcut函数对数据进行分词,
import jieba
def total():
print('总评论:',len(ls))
lp=[i[0] for i in ls] #统计好评和差评的0/1列表
print('好评:',lp.count('1'))
print('差评:',lp.count('0'))
def goodcomment():
lgood=[i[1] for i in ls if i[0]=='1']
good=''.join(lgood) #好评字符串
lq = jieba.lcut(good)
d={}
for i in lq:
if len(i)>1 and i.isdigit()==False and i not in ex:
d[i]=d.get(i,0)+1
p=sorted(d.items(),key = lambda x:x[1],reverse=True)[:15]
for i in p:
print(i[0]+':',i[1])
def badcomment():
lbad=[i[1] for i in ls if i[0]=='0']
bad=''.join(lbad) #差评字符串
lt =