使用tk filedialog保存具有特定名称的文件

问题描述

是否有一种方法可以使用Filedialog将DataFrame保存到excel文件中,但是使用特定名称作为“ my_file”? 我通常使用此代码

path_to_save = filedialog.asksaveasfilename(defaultextension='.xlsx')
    df.to_excel(path_to_save,index=False)

这将打开一个窗口,我可以在其中选择文件的位置和名称,现在,我希望默认使用名称“ my_file”,这样就不必键入它了。

有办法吗?非常感谢

已保存的excel文件为空:

 a_row['column1'] = df['column1']
new_df = a_row
new_df2 = pd.DataFrame({'column2': [],'': []})
new_df3 = pd.concat([new_df,new_df2])
new_df3['column2'] = 'some value'
new_df3 = new_df3.set_index(['column1','column2'])

path_to_save1 = filedialog.asksaveasfilename(defaultextension='.xlsx',initialfile = 'my_file')
new_df3.to_excel(path_to_save1,index=False)

是否可以像在此图像中那样在列名称的顶部插入一行?我在熊猫文档中找不到与此相关的任何内容

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)