【发布时间】:2021-06-26 12:49:54
【问题描述】:
我正在尝试 azure 情感分析 api
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
credential = AzureKeyCredential("<api_key>")
endpoint="https://<region>.api.cognitive.microsoft.com/"
text_analytics_client = TextAnalyticsClient(endpoint, credential)
documents = [
"I did not like the restaurant. The food was too spicy.",
"The restaurant was decorated beautifully. The atmosphere was unlike any other restaurant I've been to.",
"The food was yummy. :)"
]
response = text_analytics_client.analyze_sentiment(documents, language="en")
result = [doc for doc in response if not doc.is_error]
for doc in result:
print("Overall sentiment: {}".format(doc.sentiment))
print("Scores: positive={}; neutral={}; negative={} \n".format(
doc.confidence_scores.positive,
doc.confidence_scores.neutral,
doc.confidence_scores.negative,
))
这段代码工作正常,但我想读取一个 df 列,获取文本情感并创建一个列来存储文本情感,你知道我该怎么做吗?我试图通过documents = df['column_name'] 和df[I],但我得到了错误
【问题讨论】:
标签: python azure sentiment-analysis azure-cognitive-services