本帖最后由 flyps 于 2020-9-23 20:12 编辑
有时因为数据过多,甚至是几十万多,光载入时间就需要几分钟,请问下面的代码,如何使用多进程提高载入的速度?谢谢!!
需载入的文件,我已上传至附件,需先解压,谢谢!!
import pandas as pd
import numpy as np
import tkinter as tk
from pandas import read_csv
from tkinter import ttk
from tkinter import filedialog
import time
root = tk.Tk()
root.geometry('300x600')
allframe = tk.Frame(root,height=300,width=600)
allframe.grid(row=0)
tree = ttk.Treeview(allframe,show='headings',height=30)
tree["columns"] = ('A','B')
tree.column("A",width=40,anchor='center')
tree.column("B",width=40,anchor='center')
tree.heading("A",text="#")
tree.heading("B",text="#")
tree.grid(row=0,column=0,sticky=tk.NSEW)
def load(treename):
x=treename.get_children()
for item in x:
treename.delete(item)
filename = filedialog.askopenfilename()
#global file
st = time.time()
file = read_csv(filename,names=['a','b'])
#print(file)
for n in range(len(file)):
file_list = list(file.iloc[n])
#print(self.file_list)
treename.insert('','end',values=file_list)
ft = time.time()
print('time:', ft - st)
theButton1 = tk.Button(allframe,text='载入',command=lambda:load(tree))
theButton1.grid(row=0,column=1,padx=25,pady=15,sticky=tk.N)
tk.mainloop()
|