大家好,
我有幾個專欄:
1-“開始日期”列
2-“結束日期”列
通常,屬於組 (2) 的每一列也應屬於組 (1),反之亦然。 所以我們應該在兩組中有相同數量的列。
但是,屬於第 1 組的列不屬於第 2 組,反之亦然。
例子: “開始日期 9899”,但“結束日期 9899”列不存在。
目標是讓這兩組相交,以便兩組中有相同的列。
我受到以下代碼的啟發:Names Default To Here(1);
dt = Current Data Table();
// build
aa_duree = Associative Array();
aa_nonduree = Associative Array();
For Each({col_name}, dt << Get Column Names("String"),
If(Word(1, col_name) == "date début",
aa_duree[Word(-1, col_name)] = col_name;
, !IsMissing(Regex(col_name, "")),
aa_nonduree[col_name] = 1;
,
continue()
);
);
show(aa_duree);
show(aa_nonduree);
aa_duree_copy = aa_duree;
aa_duree_copy << Intersect(aa_nonduree);
cols_to_keep = Insert(aa_duree_copy << get keys, aa_duree_copy << get values);
aa_duree_copy2 = aa_duree;
aa_nonduree_copy = aa_nonduree;
aa_duree_copy2 << remove(aa_nonduree);
aa_nonduree_copy << remove(aa_duree);
cols_to_remove = Insert(aa_nonduree_copy << get keys, aa_duree_copy2 << get values);
show(cols_to_keep, cols_to_remove);