我有幾個資料夾,每個資料夾內都有幾個 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 在隔離環境中填充每個數組元素,以防止線程之間出現錯誤。 它試圖避免諸如從兩個不同執行緒同時存取資料表之類的情況。 如果你找到了方法,它可能會崩潰。