以600887伊利股份为例:
import time
import akshare as ak
from snownlp import SnowNLP
stock_code = '600887'
date = time.strftime("%Y%m%d", time.localtime())
stock_news_em_df = ak.stock_news_em(symbol=stock_code)
positive = 0
negative = 0
for i in stock_news_em_df.values[:, 1]:
text = str(i)
s = SnowNLP(text)
for sentence in s.sentences:
print(sentence, SnowNLP(sentence).sentences)
#print(s.sentiments)
#print(s.keywords(3))
#print(s.summary(3))
# 小于0.4的为悲观,否则为乐观
if s.sentiments < 0.4:
print('##########悲观', i)
negative += 1
elif s.sentiments >= 0.4:
print('##########乐观', i)
positive += 1
print("乐观:悲观 比例 {}:{}".format(positive, negative))
输出:
乐观:悲观 比例 77:23