繁体   English   中英

您如何允许用户通过终端在 Python 脚本中上传 2 个 excel 文件,而不是下载新的文件文件?

[英]How do you allow users to upload 2 excel files in a Python script via terminal, than download a new file file?

我已经使用 pandas 构建了一个数据处理工具。 我的脚本需要 2 个非常大的 excel 文件(超过 17000 行)转换为 dfs 并汇总和合并 2 个数据帧。 这给我留下了最后一个df。 我的问题是我希望这个脚本被我以外的人使用。 我可以通过使用输入 function 获得某些变量的值(使用 Python 3)

例如:

WinRate = input("Enter the Win Rate Percentage:")

但我正在努力寻找一种方法来允许用户上传 2 个文件以实际运行脚本。 我希望他们能够下载后续的 output 文件。 您能给我的任何帮助将不胜感激。 谢谢。

您可以使用 Tkinter 创建一个简单的 gui。 Tkinter 有一个 function 来显示一个文件对话框。 然后,您可以向您的用户询问 2 个输入文件(一个接一个)和 output 的文件名。 然后,您可以在脚本中使用这些文件名

import tkinter
import tkinter.filedialog

root = tkinter.Tk()
root.withdraw() # Remove background screen

# Ask for name of inputfiles
excelfile1 = tkinter.filedialog.askopenfilename(parent=root, title="Select first Excel file", defaultextension = ".xlsx")
excelfile2 = tkinter.filedialog.askopenfilename(parent=root, title="Select second Excel file", defaultextension = ".xlsx")

# Ask for name of outputfile
output_excel = tkinter.filedialog.asksaveasfilename(parent=root, title="Give name of outputfile", defaultextension=".xlsx")
# ... Use excel files in the rest of your script

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM