【问题标题】:What is the solution to the error '-1073740791 (0xC0000409)' in pyqt5?pyqt5中的错误'-1073740791(0xC0000409)'的解决方案是什么?
【发布时间】:2023-03-17 03:19:01
【问题描述】:

我想在 Pyqt5 中显示数据框。但是,我收到类似“使用退出代码 -1073740791 (0xC0000409) 完成进程”的错误

用 pandas 打开 csv 文件

csv_path = os.path.expanduser("~/Desktop/dataset/traffic-crashes-vehicles-1.csv")
datac = pd.read_csv(csv_path)


class pandasModel(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

导致问题的函数标题数据函数。参数 在自我显示为黄色之后。 PyCharm。似乎缺少某些东西或 无法识别。

    def headerData(self,orientation, role,col):
        if orientation == Qt.Horizantal and role == Qt.DisplayRole:
            return self._data.columns[col]
        return None



if __name__ == '__main__':
    app = QApplication(sys.argv)
    model = pandasModel(datac)
    view = QTableView()
    view.setModel(model)
    view.resize(800,600)
    view.show()
    sys.exit(app.exec())

【问题讨论】:

    标签: python pandas dataframe pyqt pyqt5


    【解决方案1】:

    我将 col 替换为 seciton。我打印了这一部分,它的工作量与我的列数一样多,并打印了一个数值。我知道该部分正在计算列。为了从数据框中获取列,我编写了一个 for 循环并添加了该部分。现在我的列名出现了。

    def headerData(self, section, orientation, role=Qt.DisplayRole):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return datac.columns[section]
        return QAbstractTableModel.headerData(self, section, orientation, role)
    

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 2023-02-20
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 2016-06-21
      • 2019-07-02
      • 2014-12-02
      • 1970-01-01
      相关资源
      最近更新 更多