簡體   English   中英

pyqt5報錯'-1073740791(0xC0000409)'怎么解決?

[英]What is the solution to the error '-1073740791 (0xC0000409)' in pyqt5?

我想在 Pyqt5 中顯示 dataframe。但是,我收到類似“進程已完成,退出代碼為 -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

function 導致問題 header 數據 function。自檢后參數顯示為黃色。 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())

我用 seciton 替換了 col。 我打印了這一部分,它和我的列數一樣有效,並打印了一個數值。 我知道該部分正在計算列數。 為了從 dataframe 中獲取列,我編寫了一個 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM