使用時間戳刪除重複行你好,
我附有一個示例數據表,其中我希望使用 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));
讓我們知道它是否適合您。
回复:使用時間戳刪除重複行你好羅恩,
我嘗試了您的解決方案,但發現結果存在問題。
我附上了運行你的代碼的結果。 由於某種原因,它似乎沒有捕捉到幾個重複的條目。
謝謝。
回复:使用時間戳刪除重複行這有效,謝謝!