我修改了以前的脚本以满足您的新要求。
Names Default To Here( 1 );
dt = Current Data Table();
keep = {};
delete = {};
colNameList = dt << get column names( string );
numericNamesOnly = colNameList;
For( i = N Items( colNameList ), i >= 1, i--,
colNameList[i] = Uppercase( colNameList[i] );
If( Is Missing( Num( colNameList[i] ) ) == 1,
numericNamesOnly[i] = ""
);
);
While( N Items( colNameList ) > 0,
If(
Contains( colNameList[1], Uppercase( "Date début" ) ),
found = Contains( numericNamesOnly, Word( 3, colNameList[1] ) );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, numericNamesOnly[found] );
Remove From( numericNamesOnly, found, 1 );
Remove From( numericNamesOnly, 1, 1 );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 );
Remove From( numericNamesOnly, 1, 1 );
);,
Is Missing( Num( colNameList[1] ) ) == 0,
found = Contains( colNameList, Uppercase( "DATE début " ) || colNameList[1] );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, dateDebutOnly[found] );
Remove From( numericNamesOnly, found, 1 );
Remove From( numericNamesOnly, 1, 1 );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 );
Remove From( numericNamesOnly, 1, 1 );
);,
Remove From( colNameList, 1, 1 );
Remove From( numericNamesOnly, 1, 1 );
)
);
dt << delete columns(delete);
它不是漂亮的代码,但它显示了完成工作的直接方法。
注意:您的示例数据表中有错误。您有一个列名称“Datd début 952”需要更改为“Date début 952”
谢谢它有效!
我尝试使用您的脚本,但最初我不知道如何表征第二组的所有列,因为没有类似的术语。
大家好,我有一张类似这样的数据表:
数据库由 2 组组成:
- 日期(“开始日期...")
- 与操作相关的数字
我的目标是删除不在两个列组交集中的列。
也就是说,我想用脚本自动删除列:“开始日期 952”、“9950”
感谢您的帮助 !