如何從列名中具有特定關鍵字的列中找到最大/最小值你好,我正在嘗試處理資料集以查找某些列的最大值(基於列名中的某些關鍵字)。每個資料集的列數可能不同,但列名「關鍵字」保持不變。嘗試建立一個可以在不同資料集上運行的腳本。以下是一個簡單的資料表示例來說明這一點:
| 排 | 資料1_電壓_組1 | 資料1_伏特_組2 | 數據2_伏特_組1 | 資料2_伏特_組2 | 資料_當前_A_組1 | 資料_當前_A_grp2 | 資料2_當前_A_組1 | 資料2_current_A_grp2 | 最大電壓組1 | 最大目前組2 |
| A | 0.5 | 0.8 | 0.7 | 0.2 | 1.2 | 1.4 | 0.9 | 1.8 | 0.7 | 1.8 |
| B | 0.6 | 0.9 | 0.3 | 0.4 | 1 | 1.1 | 1.5 | 0.8 | 0.6 | 1.1 |
1. 需要找出列名由 volt 和 grp1 組成的列的最大值。並將該資料填入新列“max_volt_grp1”中。
2. 需要找出列名由 current 和 grp2 組成的列的最大值。並將該資料填入新列“max_current_grp2”中。
3. 預期結果在最後兩列。
謝謝。
自動化和腳本回覆:如何從列名中帶有特定關鍵字的列中找到最大/最小值以下是我如何建立 Max_volt_grp 列的方法

Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column names( string );
valueMatrix = [];
//col = "data1_volt_grp1"
For Each( {col}, colNames,
If( Contains( col, "volt" ) & Contains( col, "grp1" ),
valueMatrix = valueMatrix |/ Matrix( Column( col ) << get values )
)
);
If( Length( valueMatrix ) > 0,
dt << New Column( "Max_volt_grp1" );
:Max_volt_grp1[1] = Max( valueMatrix );
);回覆:如何從列名中帶有特定關鍵字的列中找到最大/最小值嗨,吉姆,
此解決方案取得所有行數的這些列的最大值。我正在尋找腳本來為每一行分別填充列最大值(行數也會根據資料集而不同)。期望每行的輸出與突出顯示的列一樣。感謝您的協助。

回覆:如何從列名中帶有特定關鍵字的列中找到最大/最小值我的錯誤,試試這個方法。我不喜歡使用這種 Eval(Parse()) 方法,但這是我能使其發揮作用的唯一方法。
程式碼建立一個包含建立新列所需的 JSL 的字串,然後執行該 JSL
Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column names( string );
// Build a list of the columns to be evaluated
theCols = "";
For Each( {col}, colNames,
If( Contains( col, "volt" ) & Contains( col, "grp1" ),
theCols = theCols || ", :" || col
)
);
// Create the new column and formula command, adding in the list of
// columns ceated in the above loop and then executing it
Eval(
Parse(
"dt << new column(\!"max_volt_grp1\!",formula(Max(" ||
Substr( theCols, 2 ) || ")));"
)
);回覆:如何從列名中帶有特定關鍵字的列中找到最大/最小值謝謝吉姆。腳本按預期工作。