python_PyQt5运行股票研究python方法工具V1.1_增加表格展示控件

承接 【python_PyQt5运行股票研究python方法工具V1.0】

地址 python_PyQt5运行股票研究python方法工具V1.0_程序猿与金融与科技的博客-CSDN博客

目录

 结果展示:

 代码:

示例py文件代码(计算股票日横截面数据)

参数json文件

表格控件

ExcuteShowWidget 中 process_excute_event 方法修改


 结果展示:

1 选择py文件所在目录

2 选择py文件目录后,会提起该目录下所有的py文件,放入下拉列表

3 选择要执行的方法,点击“执行”,子线程会执行对应py文件中的代码,执行完毕后会返回结果

4 返回结果为map形式,map中的key用于识别不用结果分别对应什么内容,key会在下拉列表中展示,可以通过下拉列表切换,或上一个,下一个切换表格内容

5 显示执行结果内容

 代码:

示例py文件代码(计算股票日横截面数据)

def excute_code(json_obj:dict):'''横截面股票日数据查看:param json_obj::return:'''import pandas as pdimport oscode_list = json_obj['code_list']daily_dir = json_obj['daily_dir']start_date = json_obj['start_date']end_date = json_obj['end_date']# second_level {行业名:[股票代码]}second_level = json_obj['second_level']res_target_name_map = {}df = Nonecolumn_list = ['ticker','tradeDate','o','c','h','l','turnoverVol','dealAmount','turnoverRate','negMarketValue','marketValue','chgPct','PE']for code in code_list:daily_file_path = daily_dir + os.path.sep + code + '.csv'one_df = pd.read_csv(daily_file_path,encoding='utf-8')one_df['o_date'] = pd.to_datetime(one_df['tradeDate'])one_df = one_df.loc[(one_df['o_date'] >= start_date) & (one_df['o_date'] <= end_date)].copy()one_df = one_df.loc[one_df['openPrice'] > 0].copy()one_df['o'] = one_df['openPrice'] * one_df['accumAdjFactor']one_df['c'] = one_df['closePrice'] * one_df['accumAdjFactor']one_df['h'] = one_df['highestPrice'] * one_df['accumAdjFactor']one_df['l'] = one_df['lowestPrice'] * one_df['accumAdjFactor']one_df['chgPct'] = one_df['chgPct']*100one_df['ticker'] = codeone_df.sort_values(by='o_date',ascending=False,inplace=True)one_df = one_df.loc[:,column_list]if df is None:df = one_dfelse:df = pd.concat([df,one_df])passdf_group = df.groupby(by='tradeDate')for name,group in df_group:key_name = f'{name},all'val_data = group.loc[:,column_list].values.tolist()res_target_name_map[key_name] = val_datapassfor key,val in second_level.items():df_two = df.loc[df['ticker'].isin(val)].copy()df_two_group = df_two.groupby(by='tradeDate')for name, group in df_two_group:key_name = f'{name},{key}'val_data = group.loc[:, column_list].values.tolist()res_target_name_map[key_name] = val_datapasspasstarget_style = 'table'target_data = res_target_name_mapheader_list = ['ticker','日期','开盘价','收盘价','最高价','最低价','成交量','成交笔数','日换手率','流通市值','总市值','涨跌幅','滚动市盈率']final_map = {'target_style':target_style,'target_header':header_list,'target_data':target_data}return final_map

参数json文件

{"code_list":["000025","000031","000058","000061","000068","000096","000410","000428","000503","000509","000514","000523","000536","000548","000557","000558","000565","000566","000599","000605","000632","000638","000652","000655","000701","000709","000727","000755","000758","000767","000797","000825","000850","000856","000878","000897","000898","000901","000912","000927","000952","000958","000960","000972","001896","002022","002037","002047","002061","002097","002106","002114","002160","002168","002183","002217","002278","002285","002305","002339","002343","002344","002354","002366","002400","002427","002431","002479","002480","002500","002522","002542","002573","002642","002659","002672","002673","002676","002682","002712","002722","002783","002807","600022","600037","600058","600076","600100","600108","600115","600119","600149","600150","600156","600169","600198","600202","600239","600249","600287","600292","600299","600300","600307","600320","600322","600343","600358","600376","600397","600403","600423","600433","600448","600526","600550","600601","600604","600617","600623","600626","600629","600630","600637","600648","600649","600650","600651","600653","600675","600676","600679","600684","600686","600692","600705","600708","600712","600716","600726","600743","600748","600758","600783","600798","600800","600805","600815","600825","600844","600855","600864","600871","600874","600880","600881","600889","600939","600959","600960","600981","600986","601016","601106","601168","601198","601368","601588","601600","601718","601727","601766","601857","601866","601918","601989","601991","603021","603169","603817","603999"],"daily_dir":"E:/daily/","start_date":"2023-07-01","end_date":"2023-08-11","second_level":{"\u4ea4\u901a\u8fd0\u8f93": ["000548", "000557", "000755", "002183", "002682", "600115", "600119", "600650", "600798", "601866"], "\u4f20\u5a92": ["002343", "002354", "002400", "002712", "600037", "600358", "600637", "600825", "600959", "600986", "603999"], "\u516c\u7528\u4e8b\u4e1a": ["000767", "001896", "002479", "002480", "600149", "600617", "600726", "601016", "601991"], "\u519c\u6797\u7267\u6e14": ["000972", "600108"], "\u533b\u836f\u751f\u7269": ["000566", "000952", "002022"], "\u5546\u8d38\u96f6\u552e": ["000058", "000061", "002344", "600058", "600287", "600712", "600981"], "\u56fd\u9632\u519b\u5de5": ["600150", "601989"], "\u57fa\u7840\u5316\u5de5": ["000565", "000912", "002037", "002427", "002522", "002783", "600299", "600423", "600623", "600844", "600889"], "\u5bb6\u7528\u7535\u5668": ["002676"], "\u5efa\u7b51\u88c5\u9970": ["002047", "002061", "002431", "002542", "600629", "600939"], "\u623f\u5730\u4ea7": ["000031", "000514", "000558", "000797", "000897", "002285", "002305", "600239", "600322", "600376", "600604", "600648", "600649", "600675", "600684", "600692", "600708", "600716", "600743", "600748", "601588"], "\u6709\u8272\u91d1\u5c5e": ["000758", "000878", "000960", "002114", "002160", "601168", "601600"], "\u673a\u68b0\u8bbe\u5907": ["000410", "000856", "000927", "002097", "002278", "600169", "600202", "600320", "600343", "600783", "600815", "601106", "601766", "603169"], "\u6c7d\u8f66": ["000599", "000901", "600626", "600653", "600679", "600686", "600960"], "\u7164\u70ad": ["600397", "600403", "600758", "601918"], "\u73af\u4fdd": ["000068", "000605", "002573", "002672", "600292", "600526", "600874", "601368", "603817"], "\u7535\u529b\u8bbe\u5907": ["002168", "002339", "002366", "600550", "601727"], "\u7535\u5b50": ["000509", "000536", "000701", "000727", "002106", "002217", "600601", "600651"], "\u77f3\u6cb9\u77f3\u5316": ["000096", "600800", "600871", "601857"], "\u793e\u4f1a\u670d\u52a1": ["000428", "002659", "600880"], "\u7eba\u7ec7\u670d\u9970": ["000850", "002722", "600156", "600448", "600630", "601718"], "\u7efc\u5408": ["000025", "000632", "000652", "600676", "600805", "600881"], "\u7f8e\u5bb9\u62a4\u7406": ["000523", "600249"], "\u8ba1\u7b97\u673a": ["000503", "000638", "002642", "600100", "600855"], "\u8f7b\u5de5\u5236\u9020": ["600076", "600433", "603021"], "\u901a\u4fe1": ["600198"], "\u94a2\u94c1": ["000655", "000709", "000825", "000898", "600022", "600307"], "\u94f6\u884c": ["002807"], "\u975e\u94f6\u91d1\u878d": ["000958", "002500", "002673", "600705", "600864", "601198"], "\u98df\u54c1\u996e\u6599": ["600300"]}
}

表格控件

class TableNodeWidget(QtWidgets.QWidget):def __init__(self):super().__init__()self.init_data()self.init_ui()passdef init_data(self):self.whole_data:Dict = Noneself.target_name_list: List = Noneself.current_target_name: str = Noneself.please_select_str: str = '-- 请选择 --'passdef init_ui(self):pre_btn = QtWidgets.QPushButton('上一个')pre_btn.clicked.connect(self.pre_btn_clicked)self.target_combox = QtWidgets.QComboBox()self.target_combox.currentTextChanged.connect(self.target_combox_currentTextChanged)next_btn = QtWidgets.QPushButton('下一个')next_btn.clicked.connect(self.next_btn_clicked)layout_one = QtWidgets.QHBoxLayout()layout_one.addStretch(1)layout_one.addWidget(pre_btn)layout_one.addWidget(self.target_combox)layout_one.addWidget(next_btn)layout_one.addStretch(1)self.title_label = QtWidgets.QLabel()self.title_label.setAlignment(Qt.AlignCenter)self.title_label.setStyleSheet('QLabel{font-size:32px;font-weight:bold;}')tip_label = QtWidgets.QLabel('提示:最多显示500条数据')self.table = QtWidgets.QTableWidget()layout = QtWidgets.QVBoxLayout()layout.addLayout(layout_one)layout.addWidget(self.title_label)layout.addWidget(tip_label)layout.addWidget(self.table)self.setLayout(layout)passdef set_data(self,data:Dict):self.table.clear()self.target_combox.clear()header = data['header']self.whole_data = data['data']self.target_name_list = list(self.whole_data.keys())self.current_target_name = self.target_name_list[0]self.target_combox.addItem(self.please_select_str)self.target_combox.addItems(self.target_name_list)self.table.setColumnCount(len(header))self.table.setHorizontalHeaderLabels(header)self.fill_table_content()passdef fill_table_content(self):data = self.whole_data[self.current_target_name]self.title_label.setText(self.current_target_name)self.table.setRowCount(len(data))for i_r, row in enumerate(data):for i_c, col in enumerate(row):self.table.setItem(i_r, i_c, QtWidgets.QTableWidgetItem(str(col)))passdef pre_btn_clicked(self):cur_i = self.target_name_list.index(self.current_target_name)if cur_i<=0:cur_i = len(self.target_name_list)-1else:cur_i = cur_i -1self.current_target_name = self.target_name_list[cur_i]self.fill_table_content()passdef next_btn_clicked(self):cur_i = self.target_name_list.index(self.current_target_name)if cur_i >= len(self.target_name_list) - 1:cur_i = 0else:cur_i = cur_i + 1self.current_target_name = self.target_name_list[cur_i]self.fill_table_content()passdef target_combox_currentTextChanged(self,txt:str):cur_txt = self.target_combox.currentText()if not cur_txt or cur_txt == self.please_select_str:returnself.current_target_name = cur_txtself.fill_table_content()pass

ExcuteShowWidget 中 process_excute_event 方法修改

    def process_excute_event(self,data:Dict):mark_str = data['mark_str']status = data['status']if status == 'success':self.excute_info_label.setText(f'{mark_str} 执行成功')ret = data['ret']target_style = ret['target_style']if target_style == 'table':# 表格类型结果pre_map = {'header':ret['target_header'],'data':ret['target_data']}node_widget = TableNodeWidget()node_widget.set_data(pre_map)self.fill_scroll_area([node_widget])passelse:self.excute_info_label.setText(f'{mark_str} 失败!失败!')now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')log_str = f'{now_str}::{mark_str}::{data["msg"]}'self.log_list.append(log_str)self.thread_caculate = Noneself.progress_finished()passpass

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/94544.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

nginx代理请求到内网不同服务器

需求&#xff1a;之前用的是frp做的内网穿透&#xff0c;但是每次电脑断电重启&#xff0c;路由或者端口会冲突&#xff0c;现在使用汉土云盒替换frp。 需要把公网ip映射到任意一台内网服务器上&#xff0c;然后在这台内网服务器上用Nginx做代理即可访问内网其它服务器&#xf…

自然语言处理技术:NLP句法解析树与可视化方法

自然语言处理(Natural Language Processing,NLP)句法解析树是一种表示自然语言句子结构的图形化方式。它帮助将句子中的每个词汇和短语按照语法规则连接起来,形成一个树状结构,以便更好地理解句子的语法结构和含义。句法解析树对于理解句子的句法关系、依存关系以及语义角…

爬虫逆向实战(四)--猿人学第一题

一、数据接口分析 主页地址&#xff1a;猿人学第一题 1、抓包 当我们打开F12时会发现直接debugger了&#xff0c;是一个无限debugger&#xff0c;我们直接右键debugger那一行&#xff0c;然后选择“一律不再此处暂停”就可以了 通过抓包可以发现登录接口是api/match/1 2、…

【FAQ】安防监控视频云存储平台EasyNVR频繁离线的原因排查与解决

有用户反馈&#xff0c;在使用EasyNVR时会出现通道频繁离线的情况。针对该反馈我们立即进行了排查。 安防视频监控汇聚EasyNVR视频集中存储平台&#xff0c;是基于RTSP/Onvif协议的安防视频平台&#xff0c;可支持将接入的视频流进行全平台、全终端分发&#xff0c;分发的视频流…

Docker容器与虚拟化技术:Docker镜像创建、Dockerfile实例

目录 一、理论 1.Docker镜像的创建方法 2.Docker镜像结构的分层 3.Dockerfile 案例 4.构建Systemctl镜像&#xff08;基于SSH镜像&#xff09; 5.构建Tomcat 镜像 6.构建Mysql镜像 二、实验 1.Docker镜像的创建 2. Dockerfile 案例 3.构建Systemctl镜像&#xff08;…

DAMO-YOLO:实时目标检测设计的报告

ReadPaperhttps://readpaper.com/pdf-annotate/note?pdfId4748421678288076801eId1920373270663763712 Abstract 在本报告中&#xff0c;我们提出了一种快速准确的目标检测方法&#xff0c;称为DAMO-YOLO&#xff0c;它比最先进的YOLO系列实现了更高的性能。DAMO-YOLO 通过…

图数据库_Neo4j_Centos7.9安装Neo4j社区版3.5.4_基于jdk1.8---Neo4j图数据库工作笔记0011

首先上传安装包,到opt/soft目录 然后看一下jdk安装的是什么版本的,因为在neo4j 4以后就必须要用jdk11 以上的版本,我这里还用着jdk1.8 所以 我这里用3.5.4的版本 关于下载地址: https://dist.neo4j.org/neo4j-community-3.5.4-unix.tar.gz 然后再去解压到/opt/module目录下 …

C语言刷题训练DAY.3

1.ASCII码 解题思路&#xff1a; 这里直接以字符的形式打印就行&#xff1a; 解题代码&#xff1a; #include<stdio.h> int main() {printf("%c%c%c%c%c%c%c%c%c%c%c%c", 73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116, 33);return 0; } 2.出生日期输…

bigemap如何添加mapbox地图?

第一步 打开浏览器&#xff0c;找到你要访问的地图的URL地址&#xff0c;并且确认可以正常在浏览器中访问&#xff1b;浏览器中不能访问&#xff0c;同样也不能在软件中访问。 以下为常用地图源地址&#xff1a; 天地图&#xff1a; http://map.tianditu.gov.cn 包含&…

Android性能优化----执行时间优化

作者&#xff1a;lu人皆知 在APP做启动优化时&#xff0c;Application会做一些初始化的工作&#xff0c;但不要在Application中做耗时操作&#xff0c;然而有些初始化工作可能是很耗时的&#xff0c;那怎么办&#xff1f;初始化操作可以开启子线程来完成。 计算执行时间 常规…

Python入门【TCP建立连接的三次握手、 TCP断开连接的四次挥手、套接字编程实战、 TCP编程的实现、TCP双向持续通信】(二十七)

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是爱敲代码的小王&#xff0c;CSDN博客博主,Python小白 &#x1f4d5;系列专栏&#xff1a;python入门到实战、Python爬虫开发、Python办公自动化、Python数据分析、Python前后端开发 &#x1f4e7;如果文章知识点有错误…

使用PDF文件入侵任何操作系统

提示&#xff1a;我们8月28号开学,所以我得快点更新了&#xff0c;不能拖了&#x1f625; 文章目录 前言一、打开终端总结 前言 PDF文件被广泛应用于共享信息&#xff0c;电子邮件&#xff0c;网站或文档或存储系统的真实链接 它可以用于恶意软件的载体。 不要问我什么意思&am…

部署lawyer-llama

Git - Downloading PackageGit - Downloading PackageGit - Downloading Package 下载git&#xff0c;wget需要下载一下 &#xff08;GNU Wget 1.21.4 for Windows&#xff09;&#xff0c; Windows中git bash完全可以替代原生的cmd&#xff0c;但是对于git bash会有一些Linu…

DevExpress WinForms数据编辑器组件,提供丰富的数据输入样式!(一)

DevExpress WinForms超过80个高影响力的WinForms编辑器和多用途控件&#xff0c;从屏蔽数据输入和内置数据验证到HTML格式化&#xff0c;DevExpress数据编辑库提供了无与伦比的数据编辑选项&#xff0c;包括用于独立数据编辑或用于容器控件(如Grid, TreeList和Ribbon)的单元格。…

【AI】《动手学-深度学习-PyTorch版》笔记(十八):卷积神经网络模型(LeNet、AlexNet、VGG、NiN)

AI学习目录汇总 1、LeNet 1.1 介绍 发布时间:1989年 模型目的:识别手写数字 1.2 网络结构 1.3 定义模型 1.3.1 相关函数原型 1)nn.Conv2d:卷积层 torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, paddin

当众讲话培训的需求分析

标题&#xff1a;当众讲话培训的需求分析 摘要&#xff1a;当众讲话是现代社会中一项重要的技能&#xff0c;对于个人和职业发展都具有重要意义。然而&#xff0c;许多人面临着当众讲话的困难和挑战。本论文旨在分析当众讲话培训的需求&#xff0c;探讨为什么人们需要这种培训…

深入源码分析kubernetes informer机制(零)简单了解informer

[阅读指南] 基于kubernetes 1.27 stage版本 为了方便阅读&#xff0c;后续所有代码均省略了错误处理及与关注逻辑无关的部分。 文章目录 关于client-goInformer是什么为什么需要informerInformer工作流程后续分析计划 关于client-go client-go是kubernetes节点与服务端进行资源…

Ubuntu 20.04配置静态ip

ip配置文件 cd /etc/netplan配置 根据需求增加 # Let NetworkManager manage all devices on this system network:version: 2renderer: NetworkManager # 管理 不是必须ethernets:enp4s0: #网卡名dhcp4: no #关闭ipv4动态分配ip地址dhcp6: no #关闭ipv6动态分配…

python接口自动化测试框架2.0,让你像Postman一样编写测试用例,支持多环境切换、多业务依赖、数据库断言等

项目介绍 接口自动化测试项目2.0 软件架构 本框架主要是基于 Python unittest ddt HTMLTestRunner log excel mysql 企业微信通知 Jenkins 实现的接口自动化框架。 前言 公司突然要求你做自动化&#xff0c;但是没有代码基础不知道怎么做&#xff1f;或者有自动化…

React 高阶组件(HOC)

React 高阶组件(HOC) 高阶组件不是 React API 的一部分&#xff0c;而是一种用来复用组件逻辑而衍生出来的一种技术。 什么是高阶组件 高阶组件就是一个函数&#xff0c;且该函数接受一个组件作为参数&#xff0c;并返回一个新的组件。基本上&#xff0c;这是从 React 的组成…