刪除清單中所有列為空白的行已解決:回覆:使用 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() 元素。它將限制每個後續的選擇位置在應用選擇時僅查看先前選擇的行。
回覆:刪除清單中所有列為空的行吉姆
我相信我明白了,它生來就注定失敗。不過你的想法很好!看起來是這樣的。
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 的意義。
謝謝