python - 使用 Python 进行 Power BI 中的极性和情感分析

标签 python powerbi sentiment-analysis

我想在 Power BI 桌面中使用 Python 的 Textblob 进行情感分析。下面的代码用于创建一个单独的数据帧,我可以使用极性分数对其进行过滤。

# 'dataset' holds the input data for this script
import pandas as pd
from textblob import TextBlob
from itertools import islice

COLS = ['PersonID', 'QuestionID','Comment','subjectivity','polarity']
df = pd.DataFrame(columns=COLS)

for index, row in islice(dataset.iterrows(), 0, None):

     new_entry = []
     text_lower=str(row['Comment']).lower()
     blob = TextBlob(text_lower)
     sentiment = blob.sentiment

     polarity = sentiment.polarity
     subjectivity = sentiment.subjectivity

     new_entry += [row['PersonID'], row['QuestionID'],row['Comment'],subjectivity,polarity]

     single_survey_sentimet_df = pd.DataFrame([new_entry], columns=COLS)
     df = df.append(single_survey_sentimet_df, ignore_index=True)

但是,我想直接写入现有数据表,例如

#load in our dependencies
import pandas as pd
from nltk.sentiment.vader import SentimentIntensityAnalyzer

#load in the sentiment analyzer
sia=SentimentIntensityAnalyzer()

#apply the analyzer over each comment added to the existing table
# **I WANT TO USE A LINE LIKE THE ONE BELOW, BUT WITH THE TEXTBLOB FUNCTIONALITY ABOVE**
dataset['polairty scores'] =dataset['Message'].apply(lambda x: sia.polarity_scores(x)['compound'])

引用:https://www.absentdata.com/power-bi/sentiment-analysis-in-power-bi/

最佳答案

我假设您可以执行类似的操作并获得与第一个脚本中类似的字段。

dataset['polarity'] =dataset['Comment'].apply(lambda x: TextBlob(str(x).lower()).sentiment.polarity)
dataset['subjectivity'] =dataset['Comment'].apply(lambda x: TextBlob(str(x).lower()).sentiment.subjectivity)

关于python - 使用 Python 进行 Power BI 中的极性和情感分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60197761/

相关文章:

python - 如何在 blob 中计算情感分析

python - 奇怪的 SQLAlchemy 错误消息 : TypeError: 'dict' object does not support indexing

azure - 无法将 PowerBi 连接到 Azure 数据资源管理器,获取 "Authorization has been denied for this request"

python - 从函数返回表达式之和的 Python 方式是什么?

powerbi - 将鼠标悬停在Power BI中的文本上

powerbi - Power BI应该在星型模式模型中有粗支还是细支

java - "Enhancing"CoreNLP 情感分析结果

python-3.x - 使用python3的简单nltk情感分析代码

python - 动态更改函数 __name__ 会抛出 AttributeError : 'method' object has no attribute '__name__'

python - 通过引用返回 vector<string>