akshare股市新闻情绪判断

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-
import time
import akshare as ak
from snownlp import SnowNLP
 
# 使用snownlp
stock_code = '603777'
date = time.strftime("%Y%m%d", time.localtime())
stock_news_em_df = ak.stock_news_em(stock=stock_code)
 
for i in stock_news_em_df.values[:, 1]:
    text=str(i)
    # text = u'中国人是好人'
    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)
    elif s.sentiments>=0.4:
        print('##########积极',i)

 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 使用nltk
# from nltk.sentiment.vader import SentimentIntensityAnalyzer as sia
# import nltk
# import time
# import akshare as ak
# import jieba as jb
#
# # nltk.set_proxy('SYSTEM PROXY')
# # nltk.download('vader_lexicon')
#
# stock_code='603777'
# date=time.strftime("%Y%m%d", time.localtime())
# # sentences = ['This is the worst lunch I ever had!',
# #              'This is the best lunch I have ever had!!',
# #              'I don\'t like this lunch.',
# #              'I eat food for lunch.',
# #              'Red is a color.',
# #              'A really bad, horrible book, the plot was .']
# # '''每日快讯'''
# # stock_zh_a_alerts_cls_df = ak.stock_zh_a_alerts_cls()
# # '''当日最近 4 小时内的新闻资讯数据'''
# # js_news_df = ak.js_news(timestamp=date + "11:27:18")
# '''个股当日最近 20 条新闻资讯数据'''
# stock_news_em_df = ak.stock_news_em(stock=stock_code)
# sentences=[]
# for i in stock_news_em_df.values[:,1]:
#     seg_list = jb.cut_for_search(i)
#     print(", ".join(seg_list))
#     sentences.append(", ".join(seg_list))
# hal = sia()
# for sentence in sentences:
#     print(sentence)
#     ps = hal.polarity_scores(sentence)
#     for k in sorted(ps):
#         print('\t{}: {:>1.4}'.format(k, ps[k]), end='  ')
#     print()

 3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 使用fair
# from flair.models import TextClassifier
# from flair.data import Sentence
#
# sia = TextClassifier.load('en-sentiment')
#
#
# def flair_prediction(x):
#     sentence = Sentence(x)
#     sia.predict(sentence)
#     score = sentence.labels[0]
#     if "POSITIVE" in str(score):
#         return "pos"
#     elif "NEGATIVE" in str(score):
#         return "neg"
#     else:
#         return "neu"
#
# flair_prediction('hahahahah')

 

posted @   星涅爱别离  阅读(4007)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2020-04-09 终于理解清楚attention,利用attention对黄金价格进行预测
点击右上角即可分享
微信分享提示