0
import numpy as np
import pandas as pd
df=pd.read_excel('Finning2.xlsx',encoding='utf-8')
import nltk
nltk.download('vader_lexicon')
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()

 review = df['review']
 review = str(review).encode('utf-8')

 df['scores'] = df['review'].apply(lambda review:sid.polarity_scores(review))
4

3 回答 3

2

在应用 polar_scores 函数之前,我们需要将评论列转换为字符串

    df['score'] = df['review'].apply(lambda review:sid.polarity_scores(str(review)))
于 2020-03-22T08:12:50.800 回答
0

Try this (worked for me):

    import numpy as np
    import pandas as pd
    df=pd.read_excel('Finning2.xlsx').astype(str)
    import nltk
    nltk.download('vader_lexicon')
    from nltk.sentiment.vader import SentimentIntensityAnalyzer
    sid = SentimentIntensityAnalyzer()

    review = df['review']
    review = str(review).encode('utf-8')

    df['scores'] = df['review'].apply(lambda review:sid.polarity_scores(review))
于 2021-06-18T16:07:42.997 回答
0

我模拟了一个示例(如下所示),但无法复制您所看到的行为。您能否向我们展示数据框是如何形成的,或者您的数据的“审查”列是什么样的样本?

dict = {"population": [200.4, 143.5, 1252, 1357, 52.98]}

import pandas as pd
df = pd.DataFrame(dict)

pop = str(df['population']).encode("utf-8")
print(pop)

这是输出:

b'0     8.516\n1    17.100\n2     3.286\n3     9.597\n4     1.221\nName: area, dtype: float64'
于 2019-05-17T12:47:50.413 回答