Nachbearbeitung von Daten in einer CSV-Datei per SkriptIch habe einen Ordner mit mehreren CSV-Dateien mit ähnlicher Datenstruktur, deren Daten ich verarbeiten und die Ergebnisse in einer neuen Datei speichern muss.
Jede CSV-Datei hat zwei Spalten. Ich muss die Daten in der zweiten Spalte wie folgt verarbeiten:
- Benennen Sie die zweite Spalte als Artikel
- Führen Sie den folgenden Vorgang für alle Zeilen aus und erstellen Sie eine neue Spalte x mit der folgenden Formel: 36 + -19,5 * :items+ 49,99 *: Artikel * : Artikel * : Artikel
- Führen Sie den folgenden Vorgang für alle Zeilen der Spalte x aus, um Spalte y zu erstellen:
Mittelwert( :x[Index( Row() - 4, Row() )] ) - Ermitteln Sie den Mittelwert und das Maximum der Spalte y
- Speichern Sie die Werte „mean“ und „max“ in der Datei und wiederholen Sie den gleichen Vorgang auch für andere Dateien Pfa-Beispiel-CSV-Datei.
Ich versuche etwas wie unten, aber da ich nur ein Anfänger bin, kannst du mir bitte helfen
// 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 );
);
Verbraucher- und MarktforschungInhaltsorganisationDatenzugriffDatenmischung und -bereinigungQualitäts- und VerfahrenstechnikErgebnisse teilen und kommunizierenBetreff: Nachbearbeitung von Daten in einer CSV-Datei per SkriptDies bietet eine gute Grundlage zur Lösung des ProblemsBetreff: Nachbearbeitung von Daten in einer CSV-Datei per SkriptVielen Dank für die Optimierung und Behebung des Fehlers, sehr hilfreich!!Betreff: Nachbearbeitung von Daten in einer CSV-Datei per SkriptDu bist so nah dran.......
Sie scheinen dabei zu sein, die gewünschten Statistiken nach dem Einlesen jeder CSV-Datei in eine Liste einzutragen.Ihre Syntax dafür ist falsch, und meiner Meinung nach müssen Sie die Werte nicht in eine Liste, sondern direkt in Ihre Übersichtstabelle einfügen.Wenn Sie Statistiken für eine Spalte berechnen, müssen Sie außerdem die Spaltenform der Statistik verwenden (z. B. Col Max() ).Wenn Sie schließlich die Verarbeitung der CSV-Datei abgeschlossen haben und diese nicht länger hängen bleiben muss, können Sie sie einfach schließen.Ich habe eine Zeile hinzugefügt, die das tun würde, aber ich habe sie auskommentiert.Entfernen Sie einfach das //, wenn es wirksam werden soll.
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 );
);
Betreff: Nachbearbeitung von Daten in einer CSV-Datei per SkriptDieser Code war für mich sehr hilfreich für den Einstieg.Der folgende Code funktioniert perfekt. Mit „Speichern“ meine ich, dass ich eine Übersichtstabelle erstellen muss, die den Mittelwert und das Maximum der Spalten-AV jeder CSV-Datei enthält. Wie kann ich das tun?
Ich habe versucht: dt << Add Rows( {MovAvgMean = Mittelwert(:av) , MovAvgMax = Max(:av)} ); // Einzelliste
Aber es funktioniert nicht, da ich eine Fehlermeldung erhalte
Name ungelöst: av{1} beim Zugriff oder bei der Auswertung von '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
Betreff: Nachbearbeitung von Daten in einer CSV-Datei per SkriptWenn Sie gerade erst anfangen, sollten Sie dies schrittweise tun und verstehen, wie die einzelnen Teile funktionieren. Verwenden Sie „Hilfe > Skriptindex“ und „Hilfe > Bücher > Skripthandbuch“, um nachzuschlagen.
Der folgende Code sollte Ihnen den Einstieg erleichtern, und Sie können möglicherweise den Rest erledigen. Sie müssen genauer sagen, was Sie unter „Speichern des Werts“ verstehen. . . in die Datei einfügen'.
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));
);