删除列表中所有列为空的行已解决:回复:使用 JSL 删除具有一个或多个空值的行 - 第 2 页 - JMP 用户社区
根据以上讨论,我有一个删除空行的脚本,但它似乎删除了列出的任何列中为空的行,而我想删除列出的所有列中为空的行。
谢谢
// Get the current data table
dt = Current Data Table();
// Get all column names as strings
cnmes = dt << Get Column Names("string");
// Initialize Start and End indices
Start = .;
End = .;
// Find the index of the "Start" column
For(i = 1, i <= N Items(cnmes), i++,
If(Contains(cnmes[i], "Start"),
Start = i + 1;
Break(); // Exit loop once found
);
);
// Find the index of the "End" column
For(j = 1, j <= N Items(cnmes), j++,
If(Contains(cnmes[j], "End"),
End = j-1;
Break(); // Exit loop once found
);
);
datacols = {};
For(k = start, k <= End, k++,
Insert into (datacols, cnmes[k]) // Determine Data Columns
);
keeprows = Loc Nonmissing( datacols );
dt << select rows( keeprows ) << invert Row Selection << delete rows;
自动化和脚本回复:删除列表中所有列为空的行您是否已经对 JSL 进行了足够的研究,从而了解了为什么它不能完成您需要它做的事情?
请参阅“选择位置”中的脚本指南
您需要找到 datacols 中第一列缺少值的所有行,然后从该行列表中选择第二列缺少值的行,然后选择第三列,依此类推,直到到达 datacols 列表中的最后一列。
此后剩下的行将仅是 datacols 中所有列都缺少值的行。
然后您要做的就是删除剩余的行。
查看 Select Where() 函数的 Current Selection() 元素。它将限制每个后续 Select Where 在应用选择时仅查看先前选定的行。
回复:删除列表中所有列为空的行吉姆
我想我明白了,它天生注定要失败。不过你的想法很棒!看起来是这样的。
dt = Current Data Table();
// Get all column names as strings
cnmes = dt << Get Column Names("string");
// Initialize Start and End indices
Start = .;
End = .;
// Find the index of the "Start" column
For(i = 1, i <= N Items(cnmes), i++,
If(Contains(cnmes[i], "Start"),
Start = i + 1;
Break(); // Exit loop once found
);
);
// Find the index of the "End" column
For(j = 1, j <= N Items(cnmes), j++,
If(Contains(cnmes[j], "End"),
End = j-1;
Break(); // Exit loop once found
);
);
For(l = Start, l <= End, l++,
full_rows = dt << get rows where( !Is Missing( As Column(cnmes[l]) ) );
For Each Row(If(is missing(cnmes[i]), Remove From(full_rows))));
dt << Select Rows(full_rows) << Invert Row Selection << Delete Rows;回复:删除列表中所有列为空的行这行得通吗?我看不懂。你把每一列都单独处理了。你重置了每一列的 full_rows。
下面是使用多个 select where() 的示例,以缩小要选择的行的范围
names default to here(1);
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
// Select all males
dt << select where( :Sex == "M");
// From all of the selected males, select all of the 12 year olds
dt << select where( :age == 12, Current Selection("Restrict"));回复:删除列表中所有列为空的行我不太确定脚本的第一部分发生了什么,或者它与这个问题有什么关系(创建列表?)但你可以这样做:使用 JMP 平台(缺少数据模式),选择位置(就像 Jim 建议的那样)或者例如使用数据表下标 + 循环/数据表下标 + 一些矩阵运算。
首先,我会尝试使用 JMP 提供的缺失数据平台。看看它是否能用于此(可以),然后再研究 Jim 建议的“选择位置”选项。在您能够编写脚本并理解 Jim 的建议如何运作之后,如果您仍然感兴趣,就可以开始研究我下面建议的数据表订阅选项。
缺失数据模式
使用 JMP > 输入和编辑数据 > 组织数据表中的数据 > 查看数据表中缺失数据的模式
脚本指南 > 数据表 > 高级数据表脚本 > 查找缺失数据模式


这使用矩阵运算,我认为它应该可以工作
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(11),
Compress File When Saved(1),
New Column("Column 1", Character, "Nominal", Set Values({"", "", "aa", "", "a", "a", "", "a", "", "a", ""})),
New Column("Column 2", Character, "Nominal", Set Values({"", "a", "a", "a", "a", "", "", "a", "a", "", ""})),
New Column("Column 3", Character, "Nominal", Set Values({"a", "", "a", "", "a", "", "a", "", "", "", "a"}))
);
cols_to_check = {"Column 2", "Column 3"};
m = Matrix(IsMissing(dt[0, cols_to_check]));
rows_to_delete = Loc(V Sum(m`) == 2);
dt << select rows(rows_to_delete); // for demo purposes
dt << Delete Rows(rows_to_delete); // use this in real use case
这将循环遍历行并检查缺失值
rows_to_delete = {};
For Each Row(dt,
m = Loc Nonmissing(dt[Row(), cols_to_check]);
If(N Items(m) == 0,
Insert Into(rows_to_delete, Row());
);
);
dt << Select Rows(rows_to_delete);
回复:删除列表中所有列为空的行缺失(列表)和缺失(矩阵)
很好!——而且出乎意料。


是否有一个总体概述,哪些 JSL 函数可以“矢量化”?
回复:删除列表中所有列为空的行我以为这个脚本可以运行,但正如你指出的那样,它有一个缺陷。我尝试了@Jarmo 的想法,虽然可以运行,但它并没有帮我填充矩阵。
// Get the current data table
dt = Current Data Table();
// Get all column names as strings
cnmes = dt << Get Column Names("string");
// Initialize Start and End indices
Start = .;
End = .;
// Find the index of the "Device 2" column
For(i = 1, i <= N Items(cnmes), i++,
If(Contains(cnmes[i], "Device 2"),
Start = i + 1;
Break(); // Exit loop once found
);
);
// Find the index of the "Process Script" column
For(j = 1, j <= N Items(cnmes), j++,
If(Contains(cnmes[j], "start_date"),
End = j-1;
Break(); // Exit loop once found
);
);
datacols = {};
For(k = start, k <= End, k++,
Insert into (datacols, cnmes[k]) // Determine Data Columns
);
m = Matrix(IsMissing(dt[0, datacols]));
rows_to_delete = Loc(V Sum(m`) == 2);
dt << select rows(rows_to_delete); // for demo purposes
dt << Delete Rows(rows_to_delete); // use this in real use case
回复:删除列表中所有列为空的行你的数据列是否包含你想要的内容?此外,你还需要调整 2 以适应你的数据,例如动态选项
rows_to_delete = Loc(V Sum(m`) == N Items(cols_to_check));
可能是个好主意
回复:删除列表中所有列为空的行贾尔莫
这招奏效了。其实我很好奇“2”的含义。
谢谢