如何使用情感分析读取和识别Excel文件中的数据

时间:2019-02-21 11:02:53

标签: python pandas xlsx sentiment-analysis textblob

将熊猫作为pd导入

从熊猫导入ExcelWriter

从熊猫导入ExcelFile

从pandas.tests.test_downstream导入df

从textblob导入TextBlob

pos_count = 0 pos_correct = 0

以open('Book1.xlsx',encoding =“ utf-8”)为f:

reader = pd.read_excel(f) #sheet_name='Sheet1'
for line in reader.index:
    analysis = TextBlob(df['title'])
    if analysis.sentiment.polarity >= 0.5:
        if analysis.sentiment.polarity > 0:
            pos_correct += 1
        pos_count +=1

neg_count = 0 neg_correct = 0

print(“ Positive precision = {}%via {} samples” .format(pos_correct / pos_count * 100.0,pos_count))

0 个答案:

没有答案