将熊猫作为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))