0

I have a function to choose an excel file through the file explorer in tkinter:

import pandas as pd 
from tkinter import *
from tkinter import filedialog

def fileopen():
  filepath = filedialog.askopenfilename(filetypes=(("xlsx", "*.xlsx"), ("all files", "*.*"))) #windows file explorer
  label = Label(window, text=filepath)  #label to return file's directory path
  label.pack()
  label.place(x=200, y=80)
  df = pd.read_excel(filepath) 

This process is extremely slow. I click on the excel file and have to wait for 10-15 seconds for the path to show on my label. But when I removed the pd.read_excel() part:

def fileopen():
  filepath = filedialog.askopenfilename(filetypes=(("xlsx", "*.xlsx"), ("all files", "*.*")))
  label = Label(window, text=filepath) 
  label.pack()
  label.place(x=200, y=80)

it would return the path of my excel file in an instant, so the slowness lies in the pandas function. But I can't remove it or my program won't work at all. How can I get around this?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Moon
  • 305
  • 1
  • 2
  • 11
  • You could delay pd.read _excel until after you return and update the user interface. Show a "Please Wait" then start reading. – Dave S May 14 '21 at 23:47
  • I found out that pd.read_excel for xlsx is much slower than pd.read_csv. I converted my xlsx file into a csv one and is much faster now, although a ton of new more problemas showed up – Moon May 15 '21 at 00:16
  • duplicate question , here are ideas to speed up pd.read_excel https://stackoverflow.com/questions/28766133/faster-way-to-read-excel-files-to-pandas-dataframe/28769537#28769537 – Avinash_cdns May 15 '21 at 01:24

0 Answers0