使用时间戳删除重复行你好,
我附加了一个示例数据表,其中我希望使用时间戳、工具列删除数据集中的重复行。
重复的标准:
同一工具上 6 分钟内的时间戳被视为重复,必须删除这些行。
有人可以帮助如何在 JSL 中实现这一点吗?
谢谢!
@tx尼尔森
高级统计建模自动化和脚本编写消费者和市场研究大规模定制视窗回复:使用时间戳删除重复行谢谢@psundar6让我知道。有一个错字,现在我已经编辑了脚本。
回复:使用时间戳删除重复行这有效,谢谢!
回复:使用时间戳删除重复行你好罗恩,
我尝试了您的解决方案,但发现结果存在问题。
我已附上运行您的代码的结果。 由于某种原因,它似乎没有捕获几个重复的条目。
谢谢。
回复:使用时间戳删除重复行你好@psundar6 ,
@tx尼尔森提供了一个非常好的解决方案。
使用表排序和列公式的替代方法可以交互地或通过编写脚本来完成,如下所示:
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));
让我们知道它是否适合您。
回复:使用时间戳删除重复行我相信这将为您提供如何处理您的问题的示例
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++;
);