多個 CSV 文件的摘要我如何將 JMP 定向到我桌面上包含大約 400 個 CSV 文件(如數據庫)的文件夾、創建一堆列並創建一個每個文件 1 行的匯總表? 我可以單獨執行此操作,但這需要很長時間,我希望我可以開發一個腳本來實現自動化。
回复:多個 CSV 文件的摘要你是對的.....感謝你發現錯誤
我修改了我的原始條目以更正您發現的錯誤
回复:多個 CSV 文件的摘要我想你是想附加匯總表而不是數據表?
Names Default To Here( 1 );
dir = Pick Directory();
files = Files In Directory( dir );
dt = New Table( "concat", New Column( "File", character ) );
For( i = 1, i <= N Items( files ), i++,
If( Ends With( files[i], "csv" ), //just a check to make sure it's a csv
// Open the file
dt1 = Open( dir || files[i] );
//Get all of the numeric columns from the just opened file
thecolumns = dt1 << get column names( numeric );
// Create an output table of one row that contains the summary
// As many stats as desired can be added to the below to get all of the
// ones that are needed
dt1 << Summary( Mean( Eval( thecolumns ) ), Freq( "None" ), Weight( "None" ), output table name("tmpdt"));
// Add the summary table to the summary table
dt << concatenate( Data Table("tmpdt"), append to first table );
// Since what is wanted is the ID, not the file name, and the ID is
// the Sheeet name in the Excel spreadsheet, one has to get that value
// the the name of the data table, since that is where JMP 13 places the
// sheet name
dt:File[N Rows( dt ) ] = dt1 << Get Name;
// Close the no longer needed raw data table
Close( dt1, no save );
)
);回复:多個 CSV 文件的摘要這是我對所需腳本的看法。它非常簡單,可以匯總所有數字列,並將 Excel 工作表名稱作為新列
下面是根據下一個回復發現的問題編輯的
Names Default To Here( 1 );
dir = Pick Directory();
files = Files In Directory( dir );
dt = New Table( "concat", New Column( "File", character ) );
For( i = 1, i <= N Items( files ), i++,
If( Ends With( files[i], "csv" ), //just a check to make sure it's a csv
// Open the file
dt1 = Open( dir || files[i], private );
//Get all of the numeric columns from the just opened file
thecolumns = dt1 << get column names( numeric );
// Create an output table of one row that contains the summary
// As many stats as desired can be added to the below to get all of the
// ones that are needed
dt2 = dt1 << Summary( Mean( Eval( thecolumns ) ), Freq( "None" ), Weight( "None" ) );
// Add the summary table to the summary table
dt << concatenate( dt2, append to first table );
// Since what is wanted is the ID, not the file name, and the ID is
// the Sheeet name in the Excel spreadsheet, one has to get that value
// the the name of the data table, since that is where JMP 13 places the
// sheet name
dt:File[N Rows( dt ) ] = dt1 << Get Name;
// Close the no longer needed raw data table
Close( dt1, no save );Close( dt2, no save );
)
);
回复:多個 CSV 文件的摘要這是文斯回應的變體;這允許在每個文件中使用不同的列名。
Names Default to here(1);
dir = pick directory();
files = files in directory(dir);
//table to hold summary data
dts = New Table("Summary", New Column("filename", character));
for(i=1, i<=nitems(files), i++, //for each filename
if(endswith(files[i], "csv"), //if file is a csv
//open the file
dt1 = open( dir||files[i], private );
//add a row to the summary table
dts << Add Rows(1);
//save the filename to the data table
Column( dts, "filename" )[i] = files[i];
//get list of columns
cols = dt1 << Get Column Names();
//for each column
for ( c=1, c <= N Items(cols), c++,
//add mean column to summary table if it isn't already there
if ( Contains( dts << Get Column Names(); , Parse( Char( cols[c] ) || "_mean" ) ) < 1,
dts << New Column( Char( cols[c] ) || "_mean" );
);
//find the mean and write it to summary table
Column( dts, Char( cols[c] ) || "_mean" )[i] = ColMean( Column( dt1, cols[c] ) );
//add max column to summary table if it isn't already there
if ( Contains( dts << Get Column Names(); , Parse( Char( cols[c] ) || "_max" ) ) < 1,
dts << New Column( Char( cols[c] ) || "_max" );
);
//find the max and write it to summary table
Column( dts, Char( cols[c] ) || "_max" )[i] = ColMax( Column( dt1, cols[c] ) );
); //end loop each column
//close file
close(dt1, no save);
); //end check for csv
); //end loop for each file回复:多個 CSV 文件的摘要怎麼總結的?
回复:多個 CSV 文件的摘要CSV 文件中的數據如下所示。 文件名也是患者標識符。 我怎樣才能讓它按列標題進行匯總,並在一列中創建一個包含文件標識符的匯總數據表? 您可以在屏幕截圖的底部看到文件名的樣子。
我可以將所有 CSV 轉換為 JMP 文件嗎? 只是不確定它會有所幫助。
有誰知道數據表工具加載項是否適用於這種情況?
回复:多個 CSV 文件的摘要你能給兩個假表的屏幕截圖以及你想要的最終結果嗎? 我不知道你在問什麼。
回复:多個 CSV 文件的摘要抱歉耽擱了。 正在服役,必須照顧病人。 現在回到這個。
不,它們並不總是具有相同的列(A、B、C 等),但它們確實具有相同的名稱。
布萊恩
回复:多個 CSV 文件的摘要(忽略這個答案;Vince 有更好的方法。)
如果您想要每個文件的統計信息,則可以使用 Vince 答案的變體。 我還想像這些列是一致的......
path = "$desktop/csvFiles/";
files = Files In Directory( path );
answers = New Table( "Summary",
New Column( "N Rows", Numeric, "Continuous", Format( "Fixed Dec", 12, 0 ), Set Values( [] ) ),
New Column( "Mean(x)", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "Mean(y)", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "Mean(z)", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "sourceFile", character )
);
For( iFile = 1, iFile <= N Items( files ), iFile += 1,
file = path || files[iFile];
dt = Open( file, "text" );
dt2 = dt << Summary( Mean( :x ), Mean( :y ), Mean( :z ), Freq( "None" ), Weight( "None" ) );
answers << addrows( 1 );
answers:sourceFile = file || " " || Format( Creation Date( file ), "m/d/y h:m:s" );
answers:N Rows = dt2:N Rows[1];
answers:name( "Mean(x)" ) = dt2:name( "Mean(x)" )[1];
answers:name( "Mean(y)" ) = dt2:name( "Mean(y)" )[1];
answers:name( "Mean(z)" ) = dt2:name( "Mean(z)" )[1];
Close( dt, nosave ); // linked table closes too
);
我的文件看起來像這樣
x,y,z
1,2,3
4,5,6
我使用我手工製作的文件中的表腳本來獲取摘要腳本。 可能有更好的方法來複製變量;在 JMP 13 中,您可以使用這些想法這裡在一個語句中分配整行。
回复:多個 CSV 文件的摘要所以我對此做了一些假設。 我可以離開了。
所有 csv 文件都具有相同的列。
您想要為每個文件的每一列創建一個匯總摘要(例如平均值)。
Names Default to here(1);
dir = pick directory();
files = files in directory(dir);
dt = New Table("concat", New Column("File", character));
for(i=1, i<=nitems(files), i++,
if(endswith(files[i], "csv"), //just a check to make sure it's a csv
//break();
dt1 = open(dir||files[i], private);
dt1 << New Column("File", character, set each value(files[i]));
dt<<CONCATENATE></CONCATENATE>