可怕的标题...我正在尽力解释我要做什么...
本质上,我具有许多用户定义功能的脚本。它从各种csv文件中获取数据,总而言之,它会将单个csv文件吐出到某个输出文件夹中。没关系,但是我需要使用该输出文件来生成ANOTHER输出,基本上是对原始输出文件进行转换。现在,我可以通过简单地编写另一个程序包来轻松完成此操作...但是我希望在原始脚本中全部完成此操作。如果我只是从第二个软件包中复制/粘贴代码,则原始脚本根本不会读取...,因为它无法识别输出中的csv路径+文件名(我假设是因为Python同时运行所有内容因此,在Python到达代码的下一部分时,实际上尚未编写原始输出文件)。
所以,我有这样的事情:
def run_batch(x,y,z):
#bunch of code setting up/collecting configuration data and setting up a dict for settings
def construct(a,b,c):
#code detailing the calcs
return scenarios
#setup the output file paths
configuration_path = "some folder a"
data_path = "some folder b"
output_path = "some folder c"
run_batch
现在。我想操纵发送到output_path位置的输出,然后让Python在同一输出路径中创建另一个文件。我写了另一个类似的包:
def convert_data(csv_path,name1,name2):
df = pd.read_csv(csv_path + '\\' + name1)
z = some UDF that transforms the original output
outfile = open(csv_path + '\\' + name2)
df_2 = pd.DataFrame(z).T
df_2.to_csv(outfile)
outfile.close()
csv_path = "location of the output folder (output_path)"
name1 = "name of the csv file from the original output"
name2 = "name of the new csv file from this script"
这正是我想要的。但是我不希望它们在两个单独的.py文件中运行;我想将它们合并为一个.py文件
这可能吗?