使用时间戳删除重复行你好,
我附有一个示例数据表,其中我希望使用 TimeStamp,Tool 列删除数据集中的重复行。
复制标准:
同一工具上 6 分钟内的时间戳被视为重复,必须删除这些行。
有人可以帮助如何在 JSL 中实现这一目标吗?
谢谢!
@txnelson
分析数据表脚本编写视窗回复:使用时间戳删除重复行我相信这会给你一个关于如何处理你的问题的例子
Names Default To Here( 1 );
dt = Current Data Table();
// Loop through the data table deleting all duplicate rows
i = 1;
While( i <= N Rows( dt ),
// Find the upper and lower bounds to match on
lower = :timeStamp[i] - In Minutes( 6 );
upper = :timeStamp[i] + In Minutes( 6 );
// Find the rows that match
theRows = dt << get rows where( :timeStamp > lower & :timeStamp < upper );
// Remove the current row from the list. We do not want to delete it
Try( theRows[1] = [] );
// Delete the remaining rows
Try( dt << delete rows( theRows ) );
// Increment the row to work on
i++;
);
回复:使用时间戳删除重复行你好@psundar6 ,
@txnelson提供了一个很好的解决方案。
另一种使用表格排序和列公式的方法可以交互方式或通过编写脚本来完成,如下所示:
dt = current data table();
dt << Sort(
By( :TimeStamp, :Tool ),
Replace Table,
Order( Ascending, Ascending )
);
dt << New Column( "to delete",
Numeric,
"Ordinal",
Format( "Best", 12 ),
Formula( If( :Tool == Lag( :Tool, 1 ) & Date Difference( Lag( :TimeStamp, 1 ), :TimeStamp, "Minute" ) > 6, 1, 0 ), eval formula )
);
dt:to delete << suppress eval(true);
dt<< delete rows (dt<< get rows where (:to delete == 1));
让我们知道它是否适合您。
回复:使用时间戳删除重复行你好罗恩,
我尝试了您的解决方案,但发现结果存在问题。
我附上了运行你的代码的结果。 由于某种原因,它似乎没有捕捉到几个重复的条目。
谢谢。
回复:使用时间戳删除重复行这有效,谢谢!