首先,我想将数据集上传到表小部件中,首先导入pandas.read_csv
库中的数据集,然后通过to_dict()
将其传递给dict,然后将此字典追加到列表中以显示在表格小部件中。现在在表小部件中,它显示16000条记录正确,但是在16000条记录之后,它仅显示字符串记录。我在下一次迭代中使用def next()将数据上传到表中,这是一件事。 以下是代码:
def upload(self):
self.tableWidget.clear()
path = QFileDialog.getOpenFileName(self, "Open File", os.getenv('Home'),'*.csv')
with open(path) as csvfile:
reader = pd.read_csv(csvfile,header=None)
reader1=reader.to_dict(orient='reader1')
for line in reader1:
self.list_name.append(line)
self.tableWidget.setRowCount(len(self.list_name))
self.tableWidget.setColumnCount(len(self.list_name[0]))
for i,row in enumerate(self.list_name):
if i==15000:
break
else:
for j, col in enumerate(row):
#self.tableWidget.scrollToBottom()
#print(i)
item = QTableWidgetItem(row[col])
self.tableWidget.setItem(i, j, item)
def next(self):
self.tableWidget.clear()
self.start+=15000
self.end=self.start+15000
for i,row in enumerate(self.list_name):
if i not in range(self.start,self.end):
continue
else:
for j, col in enumerate(row):
item = QTableWidgetItem(row[col])
self.tableWidget.setItem(i, j, item)