对python借助百度云API对评论进行观点抽取的方法详解
作者:AnthonyHDM 时间:2023-12-06 19:42:12
通过百度云API接口抽取得到产品评论的观点,也掠去了很多评论中无用的内容以及符号,为后续进行文本主题挖掘或者规则的提取提供基础。
工具
1、百度云账号,申请应用接口(自然语言处理)
2、python3.5
以下是百度接口提供的说明:
我们使用到的可选值是13,kindle属于3C产品。
下面是代码示例:
from aip import AipNlp
import csv
import pandas as pd
from pandas.core.frame import DataFrame
""" 你的 APPID AK SK """
APP_ID = '********'
API_KEY = '********'
SECRET_KEY = '********'
client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
# 导入评论数据文件,并找到第13列(12行)的评论内容提取出来
def output():
urls = []
with open('E:\\tb_iphone8.csv', "r") as f:
reader = csv.reader(f)
for row in reader:
urls.append(row[12])
return urls
# 通过百度云提供的API对评论观点进行提取
def commentTag():
x = output()
all={}
abst=''
for i in range(10560):
text=x[i]
""" 调用评论观点抽取 """
""" 如果有可选参数 """
# 可选参数为13表示利用了3C产品的语料库
options = {}
options["type"] = 13
""" 带参数调用评论观点抽取 """
result=client.commentTag(text, options)
print(result)
if "error_code" in result.keys():
abst+=''
all['abstract'] = abst
else:
data = result['items']
items = data[0]
abst += items['abstract']
all['abstract'] = abst
return abst
if __name__ == '__main__':
ALL=commentTag()
print(ALL)
得到的结果如下:
可以看到,现在抽取出来的评论部分内容都是具有一定观点倾向的,大部分没有什么含义的评论内容已经被除去,这对后面的分析有一定的帮助。
来源:https://blog.csdn.net/AnthonyHDM/article/details/78957315
标签:python,百度云,API,观点
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
window.showModalDialog参数传递中含有特殊字符的处理方法
2024-04-18 09:48:16
python使用paramiko实现ssh的功能详解
2023-03-29 04:10:34
图片自动更新(说明)
2024-04-28 09:46:51
教你设计大型Oracle数据库
2009-07-02 12:31:00
python解决12306登录验证码的实现
2023-05-29 10:28:35
![](https://img.aspxhome.com/file/2023/1/75161_0s.jpg)
理解python中装饰器的作用
2022-01-29 07:58:01
Pytest框架 conftest.py文件的使用详解
2023-06-20 08:16:52
python基础入门详解(文件输入/输出 内建类型 字典操作使用方法)
2023-06-07 22:58:05
Django与JS交互的示例代码
2023-05-03 13:38:58
![](https://img.aspxhome.com/file/2023/1/107561_0s.png)
使用 PHP Masked Package 屏蔽敏感数据的实现方法
2023-09-03 23:49:13
Python matplotlib画图实例之绘制拥有彩条的图表
2023-01-26 02:06:25
![](https://img.aspxhome.com/file/2023/8/86268_0s.jpg)
详解Python如何实现对比两个Excel数据差异
2023-06-14 00:37:10
![](https://img.aspxhome.com/file/2023/5/104895_0s.png)
python字符串,元组,列表,字典互转代码实例详解
2022-03-01 22:51:55
Vue学习之路之登录注册实例代码
2024-04-27 16:08:32
![](https://img.aspxhome.com/file/2023/9/132979_0s.png)
Python安装及Pycharm安装使用教程图解
2023-08-01 05:38:06
![](https://img.aspxhome.com/file/2023/0/61460_0s.jpg)
浅谈Python协程asyncio
2021-01-12 21:30:32
如何将数据访问页绑定到断开连接的 ADO 记录集上?
2009-12-03 20:07:00
Python OpenCV的基本使用及相关函数
2022-11-16 11:24:55
![](https://img.aspxhome.com/file/2023/9/68819_0s.jpg)
Javascript世界的最大整数值
2008-06-23 13:23:00
浅谈python中列表、字符串、字典的常用操作
2023-02-02 23:59:15