• 用PyQt5来即时显示pandas Dataframe的数据,附qdarkstyle黑夜主题样式(美美哒的黑夜主题)


    import sys
    from qdarkstyle import load_stylesheet_pyqt5
    from PyQt5.QtWidgets import QApplication, QTableView
    from PyQt5.QtCore import QAbstractTableModel, Qt
    
    
    class QtTable(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]
            return None
    
    
    def render(df):
        app = QApplication(sys.argv)
        model = QtTable(df)
        view = QTableView()
        app.setStyleSheet(load_stylesheet_pyqt5())
        fnt = view.font()
        fnt.setPointSize(9)
        view.setFont(fnt)
        view.setModel(model)
        view.setWindowTitle('viewer')
        view.resize(1080, 400)
        view.show()
        sys.exit(app.exec_())

    如果想用PyQt5来即时显示pandas Dataframe的数据,直接call render这个function即可。

    render(df)

    完成!

  • 相关阅读:
    hbase编码
    kafka常用命令
    国产十大数据库排行榜
    After Titans
    kingbase7获取唯一索引和子分区键的view
    准提道人收孔宣
    MySQL使用全文索引
    instead of触发器实现复杂视图dml和应用逻辑
    中国oracle ace名单
    第六十象 癸亥
  • 原文地址:https://www.cnblogs.com/chenkuang/p/12235899.html
Copyright © 2020-2023  润新知