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

0

I want to display dataframe in Pyqt5. However, I get an error like 'Process finished with exit code -1073740791 (0xC0000409)'

Open csv file with pandas

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

the function causing the problem header Data function. Parameters after self show in yellow. PyCharm. Something seems missing or unidentifiable.

    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
asked on Stack Overflow Oct 25, 2020 by sanane sanane • edited Oct 25, 2020 by sanane sanane

1 Answer

0

I replaced col with seciton. I printed this section and it worked as much as my column count and printed a numerical value. I understood that section is counting columns. To get the columns from dataframe, I wrote a for loop and added the section. And now my column names appear.

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)
answered on Stack Overflow Oct 25, 2020 by sanane sanane

User contributions licensed under CC BY-SA 3.0