我想使用 Vader 对一些文本进行情感分析(但我在这里描述的问题也适用于任何词典,除了 Vader)。但是,在完成所有数据处理后,包括标记化和转换为小写(我在这里没有提到),我收到以下错误:
知道如何处理文档以便词典可以阅读文本吗?谢谢。
AttributeError:“列表”对象没有属性“编码”
with open('data_1.txt') as g:
data_1 = g.read()
with open('data_2.txt') as g:
data_2 = g.read()
with open('data_3.txt') as g:
data_3 = g.read()
df_1 = pd.DataFrame({"text":[data_1, data_2, data_3]})
df_1.head()
text
#0 [[bangladesh, education, commission, report, m...
#1 [[english, version, glis, ministry, of, educat...
#2 [[national, education, policy, 2010, ministry,...
from nltk.sentiment.vader import SentimentIntensityAnalyzer
vader = SentimentIntensityAnalyzer()
df_1['Vader_sentiment'] = df_1.text.apply(lambda x: vader.polarity_scores(x)['compound'])
AttributeError:“列表”对象没有属性“编码”