你好,
我有以下“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>