酒店评论分析

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('无数据')

扫描下方二维码图片,关注后了解更多精彩内容!!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二十四桥_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值