cipin.py-20180830

# -*- coding: utf-8 -*-
"""
Created on Tue Aug 28 15:09:32 2018

@author: wenyun.wxw
"""

data=ratecontent_less+ratecontent_jd_less #合并天猫评论和京东评论

num=len(data)
for i in range(num-1):
    if data[i]=='此用户没有填写评论!':
        del data[i]
    
def cipin(data,query):
    #count=0
    comment=[]
    for i in range(len(data)):
        for j in range(len(query)):
            if query[j] in data[i]:
                #count=count+1
                comment.append(data[i])
                break 
    return comment


#场景
q1=['卧室','床头','起床','房间','闹钟','房间']
q2=['客厅','电视']
q3=['厨房','餐桌','做饭']
#人群
q4=['老人','父母','妈妈','父亲','母亲','姥姥','奶奶','爷爷','姥爷']
q5=['孩子','小孩','宝宝','儿子','女儿','小孩']
q6=['全家','家人']

comment1=cipin(data,q1)
comment2=cipin(data,q2)
comment3=cipin(data,q3)
comment4=cipin(data,q4)
comment5=cipin(data,q5)
comment45=cipin(data,q4+q5)
comment6=cipin(data,q6)
comment456=cipin(data,q4+q5+q6)
comment56=cipin(data,q5+q6)
comment46=cipin(data,q4+q6)

#全家
comment7=[]
for i in range(len(data)):
    for qq1 in q4+q5:
        for qq2 in q6:
            if qq1 in data[i] or qq2 in data[i]:
                comment7.append(data[i])
                break
            break
        break
        
#只有老人   
comment9=[]   
for l in comment4:     
    if l not in comment5 and l not in comment7:
        comment9.append(l)
        

#只有孩子
comment10=[]   
for l in comment5:     
    if l not in comment4 and l not in comment7:
        comment10.append(l)

#普通购买者
comment8=[]
for l in data:
    if l not in comment9+comment10+comment7:
        comment8.append(l)
       
#词频
word,wordcount,wordcount_sort=fenci(comment8)

#词云
wordcloud = WordCloud(background_color="white",font_path="file:///C:/windows/Fonts/MSYH.TTC",
           width=1000, height=860, margin=2).fit_words(wordcount)
plt.imshow(wordcloud) 
plt.axis("off")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值