Riepilogo di più file CSVCome faccio a dirigere JMP in una cartella di file sul desktop che contiene circa 400 file CSV come un database, creare un gruppo di colonne e creare una tabella di riepilogo con 1 riga per file? Posso farlo individualmente, ma ci vuole sempre e speravo di poter sviluppare una sceneggiatura da automatizzare.
Ri: Riepilogo di più file CSVHai ragione ..... grazie per aver colto l'errore
Ho modificato la mia voce originale per correggere gli errori che hai trovato
Ri: Riepilogo di più file CSVPenso che intendevi aggiungere le tabelle di riepilogo invece delle tabelle di dati?
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 );
)
);Ri: Riepilogo di più file CSVEcco la mia versione della sceneggiatura necessaria. È piuttosto semplice e tutte le colonne numeriche sono riepilogate e porta il nome del foglio Excel come una nuova colonna
Di seguito viene modificato in base ai problemi riscontrati nella prossima risposta
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 );
)
);
Ri: Riepilogo di più file CSVEcco una variazione sulla risposta di Vince; questo consente nomi di colonne differenti in ogni file.
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 fileRi: Riepilogo di più file CSVRiassunto come?
Ri: Riepilogo di più file CSVEcco come appaiono i dati all'interno di un file CSV. Il nome del file è anche l'identificativo del paziente. Come posso farlo riassumere per titolo di colonna e creare una tabella dei dati riepilogati con l'identificativo del file in una colonna? Puoi vedere come appare il nome del file in fondo alla schermata.
Potrei convertire tutti i CSV in file JMP? Non sono sicuro che sarebbe d'aiuto.
Qualcuno sa se il componente aggiuntivo Data Table Tools potrebbe funzionare per questo caso?
Ri: Riepilogo di più file CSVpuoi dare uno screenshot di due tavoli falsi e che cosa vuoi che assuma il risultato finale? Non riesco a capire cosa stai chiedendo.
Ri: Riepilogo di più file CSVScusa per il ritardo. Era in servizio e dovevo prendermi cura dei pazienti. Ora torniamo a questo.
No, non hanno sempre la stessa colonna (A, B, C, ecc.) Ma hanno lo stesso nome.
Brian
Ri: Riepilogo di più file CSV(Ignora questa risposta: Vince ha un approccio molto migliore).
Una variazione sulla risposta di Vince, se vuoi le statistiche per file. Immagino anche che le colonne siano coerenti ...
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
);
i miei file sembravano così
x, y, z
1,2,3
4,5,6
Ho usato lo script di tabella da un file creato a mano per ottenere lo script di riepilogo. Potrebbe esserci un modo migliore per copiare le variabili; in JMP 13 puoi usare le idee Qui assegnare un'intera riga in una dichiarazione.
Ri: Riepilogo di più file CSVQuindi sto facendo alcune supposizioni su questo. Potrei essere fuori.
Tutti i file CSV hanno le stesse colonne.
si desidera creare un riepilogo aggregato (media, ad esempio) di ciascuna colonna per ogni file.
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>