Post elaborazione dei dati in un file CSV utilizzando lo scriptHo una cartella con file csv mutiple con struttura dati simile i cui dati ho bisogno di elaborare e memorizzare i risultati in un nuovo file.
Ogni file csv ha 2 colonne, ho bisogno di elaborare i dati nella seconda colonna come segue:
- Assegna alla seconda colonna il nome elementi
- Eseguire la seguente operazione su tutte le righe creando una nuova colonna x con la seguente formula: 36 + -19.5 *: articoli + 49.99 *: elementi *: elementi *: elementi
- Eseguire la seguente operazione su tutte le righe della colonna x creando la colonna y:
Media (: x [Indice (Riga () - 4, Riga ())]) - Trova la media e il massimo della colonna y
- Memorizza il valore medio e massimo nel file e ripeti la stessa procedura anche per altri file File CSV di esempio PFA.
Tringò qualcosa come sotto ma da solo un principiante, per favore, aiutatemi
// 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 );
);
Ri: Post elaborazione dei dati in un file CSV utilizzando lo scriptQuesto dà una buona base per risolvere il problemaRi: Post elaborazione dei dati in un file CSV utilizzando lo scriptGrazie per aver ottimizzato e risolto l'errore, molto utile !!Ri: Post elaborazione dei dati in un file CSV utilizzando lo scriptSei così vicino .......
Sembra che tu stia andando verso la messa in una lista, le statistiche che vuoi dopo ogni csv vengono lette. La tua sintassi per farlo è errata e, secondo me, non devi mettere i valori in una lista, ma piuttosto metterli direttamente nella tua tabella di riepilogo. Inoltre, quando si calcolano le statistiche su una colonna, è necessario utilizzare la forma della colonna della statistica (es Col Max ()). Infine, se una volta terminata l'elaborazione del file csv, non hai la necessità che continui a girovagare, puoi semplicemente chiuderla. Ho aggiunto una riga che lo farebbe, ma l'ho commentato. Basta rimuovere // se si desidera che abbia effetto.
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 );
);
Ri: Post elaborazione dei dati in un file CSV utilizzando lo scriptQuesto codice è stato molto utile per me per iniziare. Il codice seguente funziona perfettamente. Memorizzando voglio dire che ho bisogno di creare una tabella riassuntiva che contiene la media e la massima della colonna av di ogni file csv, come posso farlo?
Ho provato a usare: dt << Aggiungi righe ({MovAvgMean = Media (: av) , MovAvgMax = Max (: av)}); // lista singola
Ma non funziona quando ottengo l'errore
Nome non risolto: av {1} in accesso o valutazione di '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
Ri: Post elaborazione dei dati in un file CSV utilizzando lo scriptSe sei appena agli inizi, dovresti farlo per fasi, comprendendo come funziona ogni parte. Usa 'Aiuto> Scripting Index' e 'Guida> Libri> Guida allo scripting' per esaminare le cose.
Il codice qui sotto dovrebbe iniziare e potresti essere in grado di fare il resto. Dovrai essere più presenzioso riguardo a cosa intendi per 'memorizzare il valore. . . nel file '.
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));
);