嗨 - 我正在嘗試編寫一個遵循此工作流程的腳本:
1 - 在某個起始日期時間開始循環(例如 2021 年 10 月 1 日上午 11:00)。我將其稱為第 n 行。從 col1[row n] 獲取值。
2 - 轉到下一行,n+1。設置 col2 = col1 [n+1] - col1[n]。
3 - 轉到下一行,n+2,設置 col2 = col1 [n+2] - col1[n]
4 - 轉到下一行,n+3,設置 col2 = col1[ n+3] - col1[n]。繼續循環遍歷每個後續行,直到 datetime[n+k] = datetime[n] + 7 天。(請注意,隨著循環的進行,k 將根據行之間的時間增量而變化;例如,時間從一行到下一行增加 5 分鐘、15 分鐘、1 小時等,具體取決於所討論的行。)
5 - 使用在步驟 4 中獲得的新“開始日期”對每個新的一周數據重複步驟 1 到 4。繼續循環遍歷另外 7 天的數據。
6 - 重複步驟 5,直到數據表用完行。
目標是對 col1 數據進行計算,將一周的行與該週的第一行進行比較,然後在隨後的每個週(第 2 週、第 3 週、第 4 周等)一遍又一遍地重複此操作,直到所有行已處理。:)
你能給出一個包含你期望數據的小數據表嗎?或者至少您使用的數據表是什麼樣的? 聽起來像列公式將是一個更簡單的解決方案。
我想你可能會說這樣的話?
Names default to here(1);
dt = New Table( "Untitled 1133",
Add Rows( 5 ),
New Column( "Week1",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 22, 0 ),
Input Format( "d/m/y h:m:s", 0 ),
Set Values( [3716957885, 3716957886, 3716957887, 3716957888, 3716957889] )
),
New Column( "Week2",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 22, 0 ),
Input Format( "d/m/y h:m:s", 0 ),
Set Values( [3716957885, 3716957886, 3716957887, 3716957888, 3716957889] )
),
New Column( "Week3",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 22, 0 ),
Input Format( "d/m/y h:m:s", 0 ),
Set Values( [3716957885, 3716957886, 3716957887, 3716957888, 3716957889] )
)
);
nc = ncols(dt);
for(i=1, i<=nc, i++,
col_name = column(i) << Get Name(); // get the original column name
Eval(EvalExpr( // you have to do this so you can substitute in the actual col_name instead of a variable
dt << New Column(col_name || " comparison",
// just take current row minus first row
formula(Expr(column(dt, col_name))[row()]-Expr(column(dt, col_name))[1])
)
));
);
當然。謝謝你。附件是我在excel中創建的數據集片段作為示例。
謝謝文斯。我現在正在經歷這個......作為一個 JSL 新手(!),我有幾個問題可以幫助我遵循你的方法。為什麼要向新數據表添加 5 行?為什麼你需要“設定值”,為什麼選擇這五個數字?你的腳本是 3 週,但我的實際數據集大約有 120 週。
最後,腳本如何知道哪一列是要計算的值(即我的示例中的“流”)?(我的數據表的列比示例中顯示的三列多。)分配列名而不是切換列不是更容易嗎?我可能在這裡遺漏了一些東西。