Script per scorrere e raggruppare le colonne per nome, in modo dinamicoQuindi sto cercando di capirlo e non funziona del tutto.
Ho una tabella con una coppia chiave-valore che ho diviso da Tall a Wide. Finisco con circa 10.000 colonne che hanno tutte una struttura di denominazione regolare, come
"15.02.0 param1", "15.02 param2", "15.02 param3"...."15.03 param1", "15.03 param2", "15.03 param3",...
Come posso esaminare tutte queste colonne e raggrupparle dinamicamente in base al termine iniziale? cioè. tutte le colonne al 15,02% in un gruppo, tutte le colonne al 15,03%, tutte al 15,04%, ... tutte al 17,06%....e nominare il gruppo in base al numero groupby?
Il mio script raggruppa tutto in un unico gruppo. ug.
//**split Aggregate Data from TALL to WIDE, grouping WIDE columns by StepID
dt = current data table();
Summarize( dt, RecipeStepIndex = by( :RecipeStepId) );//get list of unique RecipeStepID's
//split the table TALL to WIDE
dt << Split(
Split By( :RecipeStepId, :ParameterName, :AggregateFunction ),
Split( :Value ),
Group( :Recipe, :ProcessTime, :Tool, :Chamber, :Lot, :WaferScribe ),
Output Table( "AggWide" ),
Remaining Columns( Drop All ),
Sort by Column Property,
dt << sort( by( :Recipe, :Tool, :Chamber, :Lot, :WaferScribe ))<BR />
);
dtAggWide = current data table();
ColNamesList = dtAggWide << get column names(string, continuous); //get the column names of the WIDE table
//Create an empty list for the matching columns
RecipeStepList = {};
// Find matching column names
For( i = 1, i <= N items( RecipeStepIndex ), i++,
For( j = 1, j <= N Items( ColNamesList ), j++,
If(
Contains( ColNamesList[j], RecipeStepIndex[i] ),
Insert Into( RecipeStepList, ColNamesList[j] ),
);
);
);
// If groups of columns are found, create Col groupings
If( N Items( RecipeStepList ) > 0,
dtAggWide << select columns( RecipeStepList );
dtAggWide << group columns();
);Miscelazione e pulizia dei datiRi: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicogotchya. Ho capito come far funzionare entrambe le versioni! Grazie mille e complimenti.
Per chiunque in futuro, ecco le mie versioni finite:
V1=
//**split Aggregate Data from TALL to WIDE, grouping WIDE columns by StepID
dt = current data table();
//Build and prefill an Array of names of the RecipeStepId
Summarize( dt, RecipeStepIndex = by( :RecipeStepId) );//get list of unique RecipeStepID's
aa_groups = Associative Array(RecipeStepIndex, Repeat({{}}, N Items(RecipeStepIndex)));
//split the table TALL to WIDE
dt << Split(
Split By( :RecipeStepId, :ParameterName, :AggregateFunction ),
Split( :Value ),
Group( :Recipe, :ProcessTime, :Tool, :Chamber, :Lot, :WaferScribe ),
Output Table( "AggWide" ),
Remaining Columns( Drop All ),
Sort by Column Property,
dt << sort( by( :Recipe, :Tool, :Chamber, :Lot, :WaferScribe ))
);
//Group the Cols by name of RecipeStepId
col_list = dtAggWIDE << Get Column Names("String"); //get the col list
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
If(!Contains(aa_groups, col_group),
aa_groups[col_group] = Eval List({col_name});
,
Insert Into(aa_groups[col_group], col_name);
);
);
For Each({{key, value}}, aa_groups, //perform the grouping
dtAggWide << Group Columns(key, value);
);
V2=
//**split Aggregate Data from TALL to WIDE, grouping WIDE columns by StepID
dt = current data table();
//Build and prefill an Array of names of the RecipeStepId
Summarize( dt, RecipeStepIndex = by( :RecipeStepId) );//get list of unique RecipeStepID's
aa_groups = Associative Array();
//split the table TALL to WIDE
dt << Split(
Split By( :RecipeStepId, :ParameterName, :AggregateFunction ),
Split( :Value ),
Group( :Recipe, :ProcessTime, :Tool, :Chamber, :Lot, :WaferScribe ),
Output Table( "AggWide" ),
Remaining Columns( Drop All ),
Sort by Column Property,
dt << sort( by( :Recipe, :Tool, :Chamber, :Lot, :WaferScribe ))
);
//Group the Cols by name of RecipeStepId
col_list = dtAggWide << Get Column Names("String");
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
If(!Contains(aa_groups, col_group),
aa_groups[col_group] = {};
);
Insert Into(aa_groups[col_group], col_name)
);
For Each({{key, value}}, aa_groups, //perform the grouping
dtAggWide << Group Columns(key, value);
);Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicoPenso che l'errore significhi che non hai una chiave nell'array associativo. Se hai provato il secondo codice, il tuo codice ha questa riga:
aa_groups = Associative Array(RecipeStepIndex, Repeat({{}}, N Items(RecipeStepIndex)));
è usato per inizializzare aa_groups. Anche se il RicettaStepIndex non combacia con col_group = Word(1, col_name, " "); otterrai quell'errore. Potrebbe essere necessario aggiungere una gestione extra per casi del genere (aggiungi un gruppo che raccoglierà tutte le colonne mancanti o aggiungerà solo le colonne che vengono trovate).
Questo dovrebbe saltare le colonne che non hanno un gruppo corrispondente.
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
If(!Contains(aa_groups, col_group),
aa_groups[col_group] = Eval List({col_name});
,
Insert Into(aa_groups[col_group], col_name);
);
);
Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicoOK, penso di capire cosa intendi, ero confuso sul motivo per cui stavi creando un nuovo dt, ma sembra solo per l'esempio.
il tuo secondo set di codice non sembra funzionare per me, ma il primo set ha funzionato. Qualche idea su cosa significhi questo errore?

//Group the Cols by name of RecipeStepId
col_list = dtAggWIDE << Get Column Names("String");
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
If(!Contains(aa_groups, col_group),
aa_groups[col_group] = {};
);
Insert Into(aa_groups[col_group], col_name)
);
Show(aa_groups);
For Each({{key, value}}, aa_groups,
dtAggWide << Group Columns(key, value);
);
Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicodtAggWide è presente perché è la tabella dati che contiene le colonne che desideri raggruppare. Nel codice sopra ti manca il riferimento ad esso, il modo più semplice e migliore per aggiungerlo sarebbe (questo eviterà di utilizzare Current Data Table() che potrebbe funzionare o meno):
dtAggWide = dt << Split(
Split By( :RecipeStepId, :RecipeStepName, :ParameterName, :AggregateFunction ),
Split( :Value ),
Group( :Recipe, :ProcessTime, :Tool, :Chamber, :Lot, :WaferScribe ),
Output Table( "AggWide" ),
Remaining Columns( Drop All ),
Sort by Column Property,
dt << sort( by( :Recipe, :Tool, :Chamber, :Lot, :WaferScribe ))
);
E col_list è lì per scorrere le colonne in dtAggWide e quindi aggiungere le colonne per correggere gli elenchi nell'array associativo aa_groups
Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicoHmm. Sono un po' bloccato e non sono sicuro di cosa ci fai qui.
Perché hanno ancora dtAggWide e col_list?
//*****************************************************************
//**split Aggregate Data from TALL to WIDE, grouping WIDE columns by StepID
dt = current data table();
//Build and prefill an Array of names of the RecipeStepId
aa_groups = Associative Array();
Summarize( dt, RecipeStepIndex = by( :RecipeStepId) );//get list of unique RecipeStepID's
aa_groups = Associative Array(RecipeStepIndex, Repeat({{}}, N Items(RecipeStepIndex)));
//split the table TALL to WIDE
dt << Split(
Split By( :RecipeStepId, :RecipeStepName, :ParameterName, :AggregateFunction ),
Split( :Value ),
Group( :Recipe, :ProcessTime, :Tool, :Chamber, :Lot, :WaferScribe ),
Output Table( "AggWide" ),
Remaining Columns( Drop All ),
Sort by Column Property,
dt << sort( by( :Recipe, :Tool, :Chamber, :Lot, :WaferScribe ))
);
//Group the Cols by name of RecipeStepId
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
Insert Into(aa_groups[col_group], col_name)
);
For Each({{key, value}}, aa_groups,
dtAggWide << Group Columns(key, value);
);Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicoÈ possibile "precompilare" l'array associativo, ad esempio, con i nomi delle colonne basati su RecipeStepIndex. Molto probabilmente RecipeStepIndex verrà trovato dall'inizio dei nomi delle colonne divise, quindi dovrebbe funzionare ancora.
Names Default To Here(1);
// this solution requires JMP16
dtAggWide = New Table("Untitled",
Add Rows(0),
New Column("15.02.0 param1", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.02.0 param2", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.02.0 param3", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.03 param1", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.03 param2", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);
col_list = dtAggWide << Get Column Names("String");
// first get the column group names and columns// in this solution case we use associative array
aa_groups = Associative Array();
//Summarize(dt, RecipeStepIndex = by(:RecipeStepId));//get list of unique RecipeStepID's
RecipeStepIndex = {"15.02.0", "15.03"};
aa_groups = Associative Array(RecipeStepIndex, Repeat({{}}, N Items(RecipeStepIndex)));
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
Insert Into(aa_groups[col_group], col_name)
);
For Each({{key, value}}, aa_groups,
dtAggWide << Group Columns(key, value);
);
Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicograzie, proverò a breve.
Ma per quanto riguarda la creazione dinamica dell'elenco di array di raggruppamento? Fondamentalmente, ogni valore univoco di :RecipeStepId dovrebbe essere un nome di gruppo. Ho provato a farlo all'inizio, prima di dividere il tavolo, salvandolo in "RecipeStepIndex"
Summarize( dt, RecipeStepIndex = by( :RecipeStepId) );//get list of unique RecipeStepID's
Ri: Script per eseguire il ciclo e raggruppare le colonne per nome, in modo dinamicoCi sono molti modi per farlo.
Ecco un esempio che prima costruisce i gruppi in un array associativo con la chiave come nome del gruppo e il valore è l'elenco delle colonne nel gruppo, quindi esegue il loop su quell'array associativo per raggruppare le colonne nella tabella dei dati. Per ottenere i nomi dei gruppi usiamo la funzione Word() sui nomi delle colonne. Ciò richiede JMP16 a causa dell'utilizzo di For Each
Names Default To Here(1);
// this solution requires JMP16
dtAggWide = New Table("Untitled",
Add Rows(0),
New Column("15.02.0 param1", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.02.0 param2", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.02.0 param3", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.03 param1", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("15.03 param2", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);
col_list = dtAggWide << Get Column Names("String");
// first get the column group names and columns<BR />// in this solution case we use associative array
aa_groups = Associative Array();
For Each({col_name}, col_list,
col_group = Word(1, col_name, " ");
If(!Contains(aa_groups, col_group),
aa_groups[col_group] = {};
);
Insert Into(aa_groups[col_group], col_name)
);
Show(aa_groups);
For Each({{key, value}}, aa_groups,
dtAggWide << Group Columns(key, value);
);

Ri: Script per eseguire il looping e raggruppare le colonne per nome, in modo dinamicoUn modo per effettuare la ricerca di un personaggio specifico e quindi utilizzarlo come nome del gruppo? In questo modo la lunghezza della prima sezione è dinamica?
Ri: Script per eseguire il looping e raggruppare le colonne per nome, in modo dinamicoDovresti modificare la parte in cui viene determinato col_group e poi continuare di conseguenza.