我写了一个python脚本,它使用tkinter和panda来:
在桌面上选择一个CSV文件,
输入数据,
做一些事情,
将创建的新数据帧导出到新的csv中。在
有没有一种方法可以在不需要打开pythonide并从那里运行它的情况下运行程序?
当前,当我尝试单击并运行测试仪.py程序我看到命令行(终端)框短暂打开,然后关闭,没有我的tkinter提示符或其他任何东西。在
我的目标,或者我的理想是我编写这个程序来帮助非技术性的同事自动化一些任务。有没有一种方法,我可以设置这个程序,让他们点击一个exe文件或bat文件,然后让脚本运行,收集所需的用户输入,然后输出csv文件,就像我希望的那样?在
我做了一些简短的谷歌搜索,但我没有找到一个明确的答案。在import tkinter
import csv
import pandas as pd
from tkinter import Tk
from tkinter.filedialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
df1 = pd.read_csv(filename)
df2 = df1.query("STATE != 'NY'") # stores records not in NY
df3 = df1[df1["FIRST_NAME"].str.contains(" ", regex=True)] # stores records that have a space in the first name
dferror = [df2, df3]
dferror = pd.concat(dferror).drop_duplicates().reset_index() # merges dataframes, drops duplicates
dferror.to_csv("C:\errors.csv")
编辑以添加我的导入子句