你好,
我有以下“TestData”:

1.我希望當狀態為down時單元格值為null。例如(“A status”單元格值是“down”列“A”中的值應該為 null 而不是“1334”。應該對 B、C 和 D 列執行相同的操作。
2.刪除列名中包含“status”的所有列。
輸出應該是這樣的:


3. 現在應該合併所有相同的時間戳行。預期輸出將是:(我知道我可以使用匯總 [group by and sum] 來實現這一點。 但是在 JSL 中有沒有更好的方法呢?)

我必須為多個 csv 文件執行此操作。 有人可以幫我為此編寫 JSL。
非常感謝您。
這應該為您完成,但腳本假定狀態列對應於它們之前的列。您可以通過查看狀態列的名稱並找到具有相同名稱減去“狀態”的列來做到這一點,但我認為如果假設為真,那將不必要地複雜。
dt = Current Data Table();
col_names = dt << Get Column Names(string);
//Assuming the corresponding value column for each status column is always the preceding one
//Loop backwards through the columns
for(i = N Col(dt), i>= 1, i--,
//If column name has word "status" in it
if(Contains(Lowercase(col_names[i]), "status") > 0,
//Look for instances of "{down}"
down_rows = dt << Get Rows Where( dt:(As Name(col_names[i])) == "{down}" );
//Assuming preceding column is the value column, replace {down} rows with missing
Column(dt, i-1)[down_rows] = .;
dt << Delete Columns(i);
);
);
//Create table summary to consolidate time stamp rows with same value
//Build a string that we can parse for the summary operation
remaining_cols = dt << Get Column Names("string");
summary_str = "dt_clean = dt << Summary( Group( :TimeStamp ), ";
//Loop through all columns except TimeStamp to add "Sum( <CURRENT col=""> )" to summary string
for(i = 2, i <= N Col(dt), i++,
summary_str = summary_str||"Sum( :Name(\!""||remaining_cols[i]||"\!")), ";
);
//Attach last part of script
summary_str = summary_str||"Freq( \!"None\!"),
Weight(\!"None\!"),
statistics column name format( \!"column\!" ),
Link to original data table( 0 ),
output table name( \!"CleanedData\!" ));";
//Parse and evaluate the string to create the summary table dt_new
eval(parse(summary_str));
//Delete N Rows column
dt_clean << Delete Columns(:N Rows);</CURRENT>