Home > Back-end >  How to Save DataFrame to Excel file using filedialouge in Python?
How to Save DataFrame to Excel file using filedialouge in Python?

Time:09-26

How can we write DataFrame object of Pandas using filedialouge in python tkinter.

file = filedialog.asksaveasfile(mode='w', defaultextension=".xlsx")
data.to_excel(file)

Whenever I try to write it it gives me error.

stat: path should be string, bytes, os.PathLike or integer, not _io.TextIOWrapper

I have been searching this error for hours, but the solutions are not working.

CodePudding user response:

use

file = filedialog.asksaveasfilename(defaultextension=".xlsx")

tkinter.filedialog.asksaveasfilename will return filename as string, not file object like tkinter.filedialog.asksaveasfile

CodePudding user response:

You need to use str:

data.to_excel(str(file)   '.xlsx')
  • Related