Python商品分析

Python商品分析,第1张

from aip import AipNlp

from openpyxl import load_workbook

APP_ID='26218126'

API_KEY='mwLIRaySttr4FwaMDuAx4RPA'

SECRET_KEY='Pxa8CC7o1fst3wjod2CG1O50aLB6GmWE'

client=AipNlp(APP_ID,API_KEY ,SECRET_KEY )

 

wb=load_workbook('京东评论按分类-好中差评.xlsx')

ws=wb.active

 

pos,mid,neg=0,0,0

for row in range(2,ws.max_row+1)

    comment=ws.cell(column=4,row=row).value

    option={}

    option['type']=11

    result=client.commentTag(comment,option)

    print("option:",result)

 

    if len(result['items'])==0:

        print('no comments')

    else:

        for view in result['items']:

            if view['sentiment']==2:

                print('positive information',view['prop'],view['adj'])

                pos+=1

            elif view['sentiment']==1:

                print('neutral information',view['prop'],view['adj'])

                mid+=1

            else:

                print('negative information',view['prop'],view['adj'])

                neg+=1

print("Total:",pos+mid+neg)

print('pos:total=',round(pos*100/(pos+mid+neg),2),'%')

print('mid:total=',round(mid*100/(pos+mid+neg),2),'%')

print('neg:total=',round(neg*100/(pos+mid+neg),2),'%')

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/917343.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存