複数のcsvファイルでスクリプトを循環させる方法以前の投稿のフォローアップとして、扱いにくいcsvファイルをスタックしてフォーマットするスクリプトがあります。
https://community.jmp.com/t5/Discussions/Help-doing-a-table-transform-and-converting-a-timestamp/td-p/303091
私の次の助けの質問は、これをフォルダ内のcsvのグループで繰り返し、ファイル名を列の1つとしてキャプチャし、理想的にはそれらもスタックする方法です。別名step1、step2、step3、step4ファイル。
単一のcsvをスタックすると、400k行の出力が作成されます。 これらのcsvを4つまたは8つまたは10つマージすると、クラッシュするリスクがありますか?
おそらく余分なのは、親フォルダー内の次のフォルダーを再度循環して、新しい結合されたステップファイルを作成することです。
names default to here(1);
//Prompt to select and open an MS Excel file
dt = Open( Pick File( "Select Excel File", "C:\Users\folder\", {"Excel Files|csv;xlsx;xls", "All Files|*"}, 1, 0 ), Invisible );
// Get the column names from the data table
colNames = dt << get column names;
// Remove the 1st col from the list
remove from(colNames,1,1);
// Stack the data
dtStack = dt << Stack(
columns(
colNames
),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked_Data" )
);
//label the 1st column to Lamda
:Column 1 << Set Name("Lamda");
:Lamda << Modeling Type(nominal);
// Create a new JMP DateTime column
dtStack << New Column( "Timestamp",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 26, 3 ),
Input Format( "d/m/y h:m:s", 0 ),
Formula( Informat( Word( 1, :Label, "Z" ), "d/m/y h:m:s" ) )
);
// Remove formula to convert column to static values
dtStack:Timestamp << delete formula;
// Create the Time variable column
dtstack << New Column( "Time",
Numeric,
"Continuous",
Format( "hr:m:s", 17, 3 ),
Input Format( "hr:m:s", 0 ),
Formula( Time Of Day( :Timestamp ) )
);
//Create Absolute Time column, uses if>then error checking for Lamda group changing
dtstack << New Column( "AbsTime",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 1 ),
Formula(
If( Row() == 1 | :Lamda != Lag( :Lamda ),
0,
Lag( :AbsTime ) + (:Timestamp - Lag( :Timestamp ))
)
),
);
// Remove formula to convert column to static values
dtStack:AbsTime << delete formula;
// Get rid of no longer needed "Label" column
dtStack << delete columns( "Label" );
データ表スクリプティングRe:複数のcsvファイルでスクリプトを循環させる方法基本的に、あなたがしなければならないのは、することだけです
- 「FilesInDirectory()」を使用して、処理するファイルのリストを取得します
- 最終データテーブルに使用するデータテーブルを設定します(dtFinal)
- For()ループを使用して、deStackテーブルを作成するディレクトリにあるすべてのファイルをループします
- ソース列をdtStackに追加します
- dtStackをdtFinalテーブルに連結します
- dtStackおよびdtデータテーブルを閉じます
以下は、上記の項目で変更されたスクリプトです。コードはテストされていないため、ファイルを読み取るにはディレクトリなどに追加する必要があります。それはあなたにあなたの最終製品を得るための本当に良い出発点を与えるはずです
names default to here(1);
//Prompt to select and open an MS Excel file
//dt = Open( Pick File( "Select Excel File", "C:\Users\folder\", {"Excel Files|csv;xlsx;xls", "All Files|*"}, 1, 0 ), Invisible );
// Get a list of files from the directory
fileList = Files In Directory( <PATH to="" your="" directory=""> || fileList[i] );
// Get the column names from the data table
colNames = dt << get column names;
// Remove the 1st col from the list
remove from(colNames,1,1);
// Stack the data
dtStack = dt << Stack(
columns(
colNames
),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked_Data" )
);
//label the 1st column to Lamda
:Column 1 << Set Name("Lamda");
:Lamda << Modeling Type(nominal);
// Create a new JMP DateTime column
dtStack << New Column( "Timestamp",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 26, 3 ),
Input Format( "d/m/y h:m:s", 0 ),
Formula( Informat( Word( 1, :Label, "Z" ), "d/m/y h:m:s" ) )
);
// Remove formula to convert column to static values
dtStack:Timestamp << delete formula;
// Create the Time variable column
dtstack << New Column( "Time",
Numeric,
"Continuous",
Format( "hr:m:s", 17, 3 ),
Input Format( "hr:m:s", 0 ),
Formula( Time Of Day( :Timestamp ) )
);
//Create Absolute Time column, uses if>then error checking for Lamda group changing
dtstack << New Column( "AbsTime",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 1 ),
Formula(
If( Row() == 1 | :Lamda != Lag( :Lamda ),
0,
Lag( :AbsTime ) + (:Timestamp - Lag( :Timestamp ))
)
),
);
// Remove formula to convert column to static values
dtStack:AbsTime << delete formula;
// Get rid of no longer needed "Label" column
dtStack << delete columns( "Label" );
// Add filename as a column to the data table
dtStack << new column( "Source", character, set each value( filename[i] ) );
// Concatenate to final table
dtFinal << concatenate( dtStack, append to first table(1) );
// Clean up
close( dtStack, nosave );
close( dt, nosave );
// End For() Loop
);</PATH>Re:複数のcsvファイルでスクリプトを循環させる方法複数ファイルのインポートも確認してください。 CSVファイルを読み込み、同じ列がある場合はそれらを連結し、オプションでファイル名の列を追加できます。
Re:複数のcsvファイルでスクリプトを循環させる方法驚くばかり。 動作しているようですが、最初のファイルの後にエラーが発生します。
"Name Unresolved:filenam} 1} in access or Evaluation of'filename '、filename / * ### * /"
何かご意見は?
また、フォルダの選択ポップアップを実行するようにスクリプトを調整しましたが、それは問題ではないと思います。
// Get a list of files from the directory
dir = Pick Directory( "Select a directory", "C:\Users\folder\");
fileList = Files In Directory( dir );
// Create a skeleton data table to end up being the combined data table
dtFinal = New Table("Final");
// Loop across all of the files found in the directory and read them in
For(i = 1, i <= N Items( fileList ), i++,
dt = open( dir || fileList[i] );