我有几个文件夹,每个文件夹内都有几个 CSV 文件。 每个 CSV 文件大约有 500,000 行。 我使用 JSL 脚本将每个文件夹内的所有 csv 文件连接到一个 JMP 表中。 对每个文件夹重复此过程,因此最终的串联 JMP 表数量与文件夹数量一样多。 但这需要很多时间。
我在 JSL 中搜索了并行编程,并了解了并行分配。 我需要一些关于如何将下面的脚本放入并行分配中以加速串联的指导。 我将非常感激。
path = munger(Pick Directory( "Browse to the Directory of the .txt / .csv files " ),1,"/","");
Print(dirList(path));
folderlist={};
folderlist = dirList(path);
count=nitems(folderlist);
//prefolderlist = Files In Directory( path );
//filepath = Convert File Path(path, Windows )
For( j2 = 1, count >= j2, j2++,
folderpath= path || folderlist[j2] || "/" ;
Print(folderpath);
prefilelist = Files In Directory( folderpath );
n2=nitems(prefilelist);
filelist = {};
//filter out any non-txt or csv files
For( i2 = 1, n2 >= i2, i2++,
file=(prefilelist[i2]);
If( Item( 2, prefilelist[i2], "." ) == "txt" | Item( 2, prefilelist[i2], "." ) == "csv",
Insert Into( filelist,file),
show(file)
)
);
nf=nitems(filelist); //number of items in the working list
cctable= New Table( "Combined data table ");//make an empty table
cctable<<New Column( "Source", Character, Nominal );
For( iii = 1 , iii <= nf, iii++, //this starts the first loop
filenow = ( filelist[iii] );
fileopen=(folderpath||filenow);
//dt=open(fileopen,private);
dt=open(fileopen,importset,private);//Import settings used in the open argument
New Column( "Source", Character, Nominal );
:Source << set each value( filenow );
//dt<<new column("Source", character, nominal)<<set each value(9999);
dt << Run Formulas();
//add the current table to the bottom of the combined data table
cctable << Concatenate( Data Table( dt ), Append to first table );
//don't use "Create Source Column" argument
Close( dt, NoSave );//after concatenating the table, close it and move on
);//end of the first for loop
);太感谢了。 我能够将导入多个文件合并到我的脚本中,现在它能够更快地连接表。
看一下“文件”->“多个文件导入”。 它可以挖掘嵌套目录,按文件名模式进行选择,并连接相似的文件。 而且它比在 CSV 上使用 open() 更快,通常甚至对于单个文件也是如此。 它还制作了一个可以修改和重用的脚本。 它可以添加一个包含源文件信息的列。
以交互方式开始,查找复选框以保持窗口打开,进行一些实验。
GUI 有四个过滤器,用于选择所选文件。文件夹/隐藏/递归过滤器始终可见,并且有三个复选框可以显示和使能够文件名、文件时间和文件大小过滤器。 文件列表显示选择的内容;这是不是用于选择文件。
最坏的情况是,您可以在每个目录上使用 MFI,一次一个,并且可能会获得不错的速度提升。 最好的情况是它可能会在整个目录嵌套上执行您想要的操作。
并行分配旨在填充数组并运行 JSL,该 JSL 在隔离环境中填充每个数组元素,以防止线程之间出现错误。 它试图避免诸如从两个不同线程同时访问数据表之类的情况。 如果你找到了方法,它可能会崩溃。