pyqt pandas dataframe df数据显示在QT上,表类数据的在PYQT中的导入

表类数据建议QT中的tableview ,效率更高,以下是实现方法的代码

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import akshare as ak
import time
class PdTable(QAbstractTableModel):
    def __init__(self, data):
        QAbstractTableModel.__init__(self)
        self._data = data
 
    def rowCount(self, parent=None):
        return self._data.shape[0]
 
    def columnCount(self, parent=None):
        return self._data.shape[1]
 
    # 显示数据
    def data(self, index, role=Qt.DisplayRole):
        if index.isValid():
            if role == Qt.DisplayRole:
                return str(self._data.iloc[index.row(), index.column()])
        return None
 
    # 显示行和列头
    def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self._data.columns[col]
        elif orientation == Qt.Vertical and role == Qt.DisplayRole:
            return self._data.axes[0][col]
        return None


class Stock_Index():

    def Sh_Iindex(self):
        '''返回上海证券实时涨跌幅数据,为防IP被封,每1分钟更新一次'''
        #while True:
            
        df = ak.stock_zh_index_spot()
        #df=df[df['代码']=='sh000001']
        #Value=df[df['代码']=='sh000001']['涨跌幅'].values[0]
        return df # Value

class mywindow(QWidget):


    def __init__(self):
        super().__init__()
        self.resize(500,400)
        self.btn_close = QPushButton('close',self)# 
        self.txb=QTextBrowser(self)#
        self.tableView = QTableView()
        self.tableView.setGeometry( 0,50,500,350)
        si=Stock_Index()
        df=si.Sh_Iindex()
        model=PdTable(df)
        self.tableView.setModel(model)

        dlgLayout = QVBoxLayout()
        dlgLayout.addWidget(self.tableView)
        self.setLayout(dlgLayout)

        
        
app=QApplication([])
main=mywindow()
main.show()
app.exec()

参考链接:

https://blog.csdn.net/islinyoubiao/article/details/105577081?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165322394216781483798440%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=165322394216781483798440&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-4-105577081-null-null.142v10control,157v4control&utm_term=pyqt+dataframe&spm=1018.2226.3001.4187

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值