我正在制作一个用于科学目的的桌面应用程序,我正在努力寻找有关该主题的信息。
我有扫描excel文件的特定文件夹并保存其名称和路径的代码
sample_directory_2 = []
sample_files_2 = []
for (dirpath, dirnames, filenames) in walk('./Processed'):
filenames = [f for f in filenames if not f[0] == '.']
sample_files_2.extend(filenames)
break
the_dir = "Processed"
paths_2 = [os.path.abspath(os.path.join(the_dir,filename)) for filename in os.listdir(the_dir) if not filename.startswith('.')]
sample_directory_2.append(sample_files_2)
sample_directory_2.append(paths_2)
此外,我有一段代码,从这些文件中获取数据
processed_info = []
for i in range(len(sample_directory_2[0])):
file_info = []
sample_file_2 = sample_directory_2[0][i]
sample_path_2 = sample_directory_2[1][i]
sample_info_2 = pd.read_excel(ospath(sample_path_2), header = None, sheetname = 3)
sample_info_2 = sample_info_2.iloc[0][0:3]
file_info.append(sample_file_2)
sample_info_2_list = numpy.array(sample_info_2).tolist()
file_info.extend(sample_info_2_list)
processed_info.append(file_info)
它被保存到一个数组中
[['sample1(02:03:2018 14-38).xlsx',3892.523626752876,18.64406779661017,0.6936147012986077],
['sample2(02:03:2018 14-38).xlsx',6135.581250460564,79.66101694915254,0.6072608909734578],
['sample3(02:03:2018 14-38).xlsx',3461.456815612303,5.084745762711865,0.6676008795372024],
['sample4(05:03:2018 07-28).xlsx',6135.581250460564,79.66101694915254,0.6072608909734578]]
如何将这些数据插入到QTableWidget单元格中,其中每个列表(例如:['sample1(02:03:2018 14-38).xlsx',3892.523626752876,18.64406779661017,0.6938147012986077])作为新行插入4列?
UPD:找到一种添加项目的方法
for row in range(len(processed_info)):
for column in range(len(processed_info[row])):
self.clickSample_list.setItem(row, column, QTableWidgetItem(processed_info[row][column]))
怎么可能?
发现了一个问题。
self.clickSample_list.setItem(row, column, QTableWidgetItem(processed_info[row][column]))
仅适用于字符串项,因此我将其替换为
self.clickSample_list.setItem(row, column, QTableWidgetItem(str(processed_info[row][column])))
很容易