简体   繁体   English

如何更快地将带有 Pandas 的值从 excel 导入 tkinter?

[英]How to import values from excel with pandas into tkinter faster?

guys!伙计们! How are you?你好吗? I have this code below and I'm having this trouble with the insertData function.我在下面有这个代码,我在使用insertData函数时遇到了这个问题。 This function is used to enter values from an excel spreadsheet into the tkinter treeview using Pandas.此函数用于使用 Pandas 将 Excel 电子表格中的值输入到 tkinter 树视图中。 It's almost all right, but it's too slow and I don't know how to fix it.几乎没问题,但是太慢了,我不知道如何解决。 If anyone could help me, I'd be very happy.如果有人能帮助我,我会很高兴。 Thanks in advance!提前致谢!

from tkinter import *
import ttk
import openpyxl
import pandas as pd

nuScreen = Tk()
nuScreen.title("ContrasinSystem - Usuário Comum")
nuScreen.iconbitmap("logocontransin.ico")

book = openpyxl.load_workbook('Registros.xlsx')
sheet = book.sheetnames
sh = book.active.cell

#Contador de Linhas:
wb2 = openpyxl.load_workbook('Registros.xlsx')
sheet2 = wb2.worksheets[0]

rowCount = sheet2.max_row

v = []

#Design:


class main():
    def __init__(self,tk):
        for x in range (0,len(sheet)):
            v.append(sheet[int(x)])


        self.wb2 = openpyxl.load_workbook('Registros.xlsx')
        self.sheet2 = self.wb2.worksheets[0]

        self.row_count = self.sheet2.max_row
        self.column_count = self.sheet2.max_column


        self.nuFrame = Frame(nuScreen, width = 1500, height = 450)

        self.nuFrame.pack()

        self.img = PhotoImage(file="logocontransin.png")
        self.w = Label(self.nuFrame, image = self.img)
        self.w.img = self.img
        self.w.place(x=65,y=150)


        self.srchlbl = ttk.Label(self.nuFrame, text = "Buscar:")
        self.srchlbl.place(x=25,y=75)
        self.srchetr = ttk.Entry(self.nuFrame, width = 30)
        self.srchetr.place(x=75,y=75)

        self.treeview = ttk.Treeview(self.nuFrame)
        self.treeview.place(x=300,y=75, width = 1100)

        dataVector = []      
        def columnsName():
            def Header():
                self.columnVector = []
                self.dataVector = []
                teste = []
                self.treeview.column("#0", width = 20)          
                self.columnHeader = pd.read_excel(r'Registros.xlsx', str(self.cmb.get()), header_only = True, nrows=0).columns
                for a in self.columnHeader:
                    self.columnVector.append(a)
                self.treeview.configure(columns = self.columnVector)
                for b in self.columnHeader:
                    self.treeview.heading(str(b), text = str(b))
            def insertData():
                for m in range(rowCount):
                    self.dataValues = pd.read_excel(r'Registros.xlsx',str(self.cmb.get()), skip_blank_lines=True, skiprows=0)
                for l in self.dataValues:
                    dataVector.append(l)
                self.treeview.insert("", "end",values = dataVector)
                print(self.dataValues)

            Header()
            insertData()


        self.cmbLbl = ttk.Label(self.nuFrame, text = "Assunto:")
        self.cmbLbl.place(x=1200, y=325)
        self.cmb = ttk.Combobox(self.nuFrame, values = v)
        self.cmb.place(x=1250,y=325)

        self.btncmb = ttk.Button(self.nuFrame, text = "Buscar", command = columnsName)
        self.btncmb.place(x=1320,y=375)

nuScreen.geometry("1500x450")
main(nuScreen)
nuScreen.mainloop()

How many times do you want to open a excel file for reading?你想打开多少次excel文件进​​行阅读?

def insertData():
  for m in range(rowCount):
    self.dataValues = pd.read_excel(r'Registros.xlsx',str(self.cmb.get()), 
    skip_blank_lines=True, skiprows=0)
  for l in self.dataValues:
    dataVector.append(l)
    self.treeview.insert("", "end",values = dataVector)
    print(self.dataValues)

Should you instead omit the first loop?你应该省略第一个循环吗?

def insertData():
  self.dataValues = pd.read_excel(r'Registros.xlsx',str(self.cmb.get()), 
  skip_blank_lines=True, skiprows=0)
  for l in self.dataValues:
    self.treeview.insert("", "end",values = l)
    print(self.dataValues)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过从下拉列表中选择一个因子将 excel 中的特定单元格值导入 tkinter label 框中? - How to import a specific cell values from excel into a tkinter label box by selecting a factor from dropdown? 如何更快地打开从pandas创建的excel文件? - How to open the excel file creating from pandas faster? 如何使用熊猫从excel中导入日期为索引的数据 - How to import data with dates as index from excel with pandas 从 Github 存储库将 Excel 文件导入 pandas - Import Excel file to pandas from Github repository 如何从 Excel 创建字典,并将列表作为 pandas 中的值? - How to create a dictionary from Excel with list as values in pandas? 如何使用多处理将多个Excel工作表导入到pandas中? - How to import multiple Excel sheets into pandas with multiprocessing? 将pandas表导入tkinter项目 - Import pandas table into tkinter project 从 Excel 导入格式并应用到 pandas dataframe 以导出到 ZBF57C906FA7D45566D07372E - Import formatting from Excel and apply to a pandas dataframe for export to excel 如何使用 python ZE5BA8B4C39C29BF13426EF5E0287AAA 将用户选择的 Excel 文件导入 mysql - How to Import an Excel file chosen by user to mysql using python tkinter 如何使用 ```import Tkinter``` 而不是 ```from tkinter import *``` 设置 Tkinter window 的大小? - How can I set a size for a Tkinter window using ```import Tkinter``` instead of ```from tkinter import *```?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM