2021年3月18日星期四

Is there a way to automatically add a filename extension when using the pandas df.to_csv?

I know how to use 'defaultextension' and 'filetypes', as follows:

self.filetypes = (('CSV files', '*.csv'), ('CSV files', '*.csv'))  self.result_file = fd.asksaveasfile(filetypes = self.filetypes, defaultextension = 'csv')  

I can simply add the extension when entering the filename, but I'd prefer not to do that. If I enter 'result' for my filename, I'd like for the actual filename to be result.csv.

While I'm at it, I know my filetypes specification looks a little odd, two identical options. When reading files, I couldn't figure out how to provide only one option without getting an error message. This seems to work, at least when reading. Not sure if that's part of my problem when writing.

https://stackoverflow.com/questions/66700356/is-there-a-way-to-automatically-add-a-filename-extension-when-using-the-pandas-d March 19, 2021 at 07:07AM

没有评论:

发表评论