import jieba
n = input()
with open('comment.csv', 'r', encoding='GBK') as f:
ls = [i.strip().split(',', maxsplit=1) for i in f.readlines()[1:]]
c = 0
d = 0
count = 0
ls1 = []
ls2 = []
dict1 = dict()
dict2 = dict()
ex = ['不错', '比较', '可以', '感觉', '没有',
'我们', '就是', '还是', '非常', '但是',
'不过', '有点', '一个', '一般', '下次',
'携程', '不是', '晚上', '而且', '他们',
'什么', '不好', '时候', '知道', '这样',
'这个', '还有', '总体', '位置', '客人',
'因为', '如果', '这里', '很多', '选择',
'居然', '不能', '实在', '不会', '这家',
'结果', '发现', '竟然', '已经', '自己',
'问题', '不要', '地方', '只有', '第二天',
'酒店', '房间', '虽然']
if n == '总评':
print('总评论: {}'.format(len(ls)))
for i in ls:
if i[0] == '1':
c = c + 1
else:
d = d + 1
print('好评: {}'.format(c))
print('差评: {}'.format(d))
elif n == '平均':
for i in range(0, len(ls)):
count = count + len(ls[i][1])
print(int(count / len(ls)))
elif n == '好评':
for i in range(0, len(ls)):
if ls[i][0] == '1':
result = jieba.lcut(ls[i][1])
ls1.extend(result)
for i in ls1:
t = str(i)
if len(i) < 2:
continue
if t.isdigit():
continue
if i in ex:
continue
dict1[t] = dict1.get(t, 0) + 1
list1 = [(a, b) for a, b in dict1.items()]
list1.sort(key=lambda x: x[1], reverse=True)
for i in range(0, 15):
print('{}: {}'.format(list1[i][0], list1[i][1]))
elif n == '差评':
for i in range(0, len(ls)):
if ls[i][0] == '0':
result = jieba.lcut(ls[i][1])
ls2.extend(result)
for i in ls2:
t = str(i)
if len(i) < 2:
continue
if t.isdigit():
continue
if i in ex:
continue
dict2[t] = dict2.get(t, 0) + 1
list2 = [(a, b) for a, b in dict2.items()]
list2.sort(key=lambda x: x[1], reverse=True)
for i in range(0, 15):
print('{}: {}'.format(list2[i][0], list2[i][1]))
else:
print('无数据')
扫描下方二维码,关注后了解更多精彩内容!!