スクリプトを使用したcsvファイル内のデータの後処理私は、データを処理して結果を新しいファイルに保存する必要があるデータが似たデータ構造を持つ複数のcsvファイルを含むフォルダーを持っています。
各csvファイルには2つの列があります。次のように2番目の列のデータを処理する必要があります。
- 2列目に以下の名前を付けます。アイテム
- 次の式で新しい列xを作成して、すべての行に対して次の操作を実行します。36 + -19.5 *:items + 49.99 *: アイテム *: アイテム *: アイテム
- 列xのすべての行に対して次の操作を実行して列yを作成します。
平均値(:x [インデックス(行() - 4、行())]) - 列yの平均と最大を求める
- 値meanとmaxをファイルに保存し、他のファイルについても同じ手順を繰り返します。 PFAサンプルCSVファイル。
私は以下のように何かをひいていますが、ただの初心者なのでおまけをしてください助けてください
// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );
X = N Items( files );
Y = "C:\Users\MyUserName\Documents\My Data\";
//stores the mean and max value of each file
dt = New Table( "My data file");
For( i = 1, i < X, i++,
//open jmp files for each csv files.
dt1 = Open(
Y || files[i],
//Code to add column name and the find mean and max
);
dt1 << Set Name( files[i] );
//I concatenated all the files in one jmp file and close it each time.
dt << Concatenate( Data Table( dt1 ), "Append to first table" );
Close( dt1 );
);
スクリプトを使用してcsvファイル内のデータの後処理これは問題を解決するための良い基盤を与えますスクリプトを使用してcsvファイル内のデータの後処理エラーを最適化して解決してくれてありがとう。スクリプトを使用してcsvファイル内のデータの後処理あなたはまあまあです.......
あなたはリストに入れることに向かって動いているように見えました、各csvが読まれた後にあなたが望む統計量。 それを行うためのあなたの構文は正しくありません、そして私の意見では、あなたは値をリストに入れる必要はありませんが、むしろあなたのサマリーテーブルに直接入れます。 また、列の統計を計算するときは、統計の列形式を使用する必要があります。Col Max()) 最後に、csvファイルの処理が完了したら、それをハングし続ける必要がない場合は、簡単に閉じます。 私はそれを行う行を追加しましたが、私はそれをコメントアウトしました。 有効にしたい場合は、//を削除するだけです。
Names Default To Here( 1 );
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV = Function( {path2File},
{Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
// Start your summary table
dt = New Table( "My summary file" );
dt << New Column( "MovAvgMean", Numeric );
dt << New Column( "MovAvgMax", Numeric );
// Put all the .csv files to process into a list
dir = Pick Directory(
"Directory containing your csv files",
"C:\Users\shilpajo\Documents\PV\KT\LIMC\iccMax\DIADEM\JMP\files\"
);
files = Files In Directory( dir );
For( f = N Items( files ), f >= 1, f--,
If( !Ends With( Uppercase( files[f] ), ".CSV" ),
Remove From( files, f )
)
);
// Process each file - Incomplete!
For( f = 1, f <= N Items( files ), f++,
thisTable = openMyCSV( dir || files[f] );
thisTable << New Column( "x",
Numeric,
Continuous,
Formula( 36 + -19.5 * :items + 49.99 * :items * :items * :items )
);
thisTable << New Column( "av", Numeric, Continuous, Formula( Mean( :x[Index( Row() - 9, Row() )] ) ) );
// This will insure that all formula processing is complet before the next statement is run
thisTable << run formulas;
// Add the summary statistics to the summary table
dt << Add Rows( 1 );
dt:MovAvgMean[N Rows( dt )] = Col Mean( thisTable:av );
dt:MovAvgMax[N Rows( dt )] = Col Max( thisTable:av );
// Close( thisTable, nosave );
);
スクリプトを使用してcsvファイル内のデータの後処理このコードは私が始めるのにとても役に立ちました。 以下のコードは完璧に動作します。保存することで、各csvファイルのav列の平均値と最大値を含む要約テーブルを作成する必要があるということですが、どうすればよいでしょうか。
私は試してみました:dt << Add Rows({MovAvgMean = 平均(:av) 、MovAvgMax = Max(:av)})。//単一リスト
しかし、私はエラーを受け取るようにそれは動作しません
名前未解決:アクセス中のav {1}、または 'av'の評価、:av / * ### * /
NamesDefaultToHere(1);
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV =
function({path2File}, {Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
dt = New Table( "My data file");
dt << New Column( "MovAvgMean", Numeric );
dt << New Column( "MovAvgMax", Numeric );
// Put all the .csv files to process into a list
dir = pickDirectory("Directory containing your csv files", "$DESKTOP");
files = filesInDirectory(dir);
for(f = NItems(files), f>=1, f--, if(!endsWith(uppercase(files[f]), ".CSV"), removeFrom(files, f)));
// Process each file - Incomplete!
for(f = 1, f <= NItems(files), f++,
thisTable = openMyCSV(dir||files[f]);
thisTable << newColumn("x", Numeric, Continuous, Formula(36 + -19.5 * :items + 49.99 *:items* :items* :items));
thisTable << newColumn("av", Numeric, Continuous, Formula(Mean( :x[Index( Row() - 9, Row() )] )));
dt << Add Rows( {MovAvgMean =Mean(:av), MovAvgMax = Max(:av)} ); // single list
);
// Make the summary table
スクリプトを使用してcsvファイル内のデータの後処理始めたばかりの場合は、各部分がどのように機能するかを理解しながら、段階的にこれを実行する必要があります。検索するには、[ヘルプ]> [スクリプトインデックス]と[ヘルプ]> [書籍]> [スクリプトガイド]を使用してください。
以下のコードはあなたを始めさせるべきで、あなたは残りをすることができるかもしれません。あなたは自分が何を意味するのかをもっと正確に知る必要があるでしょう。。。ファイルに '。
NamesDefaultToHere(1);
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV =
function({path2File}, {Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
// Put all the .csv files to process into a list
dir = pickDirectory("Directory containing your csv files", "$DESKTOP");
files = filesInDirectory(dir);
for(f = NItems(files), f>=1, f--, if(!endsWith(uppercase(files[f]), ".CSV"), removeFrom(files, f)));
// Process each file - Incomplete!
for(f = 1, f <= NItems(files), f++,
thisTable = openMyCSV(dir||files[f]);
thisTable << newColumn("x", Numeric, Continuous, Formula(36 + -19.5 * :items + 49.99 *:items* :items* :items));
);