如何从列名中具有特定关键字的列中查找最大/最小值你好,我正在尝试处理数据集以查找某些列的最大值(基于列名中的某些关键字)。每个数据集的列数可能不同,但列名“关键字”将保持不变。尝试创建一个可以处理不同数据集的脚本。下面是一个简单的数据表示例来说明这一点:
| 排 | 数据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 ) || ")));"
)
);回复:如何从列名中带有特定关键字的列中查找最大/最小值谢谢 Jim。脚本按预期运行。