- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Colonnes
Bonjour à tous, je dispose d’une table de données similaire à celle la :
La base de données est constitué de 2 groupes :
- Les dates ( « date début... »)
- Les numéros associés à des opérations
Mon objectif est de supprimer les colonnes qui ne sont pas dans l’intersection des deux groupes de colonnes.
C’est à dire ici, j’aimerai supprimer automatiquement avec un script les colonnes : « Date début 952 », « 9950 »
Merci pour votre aide !
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Colonnes
I reworked the previous script to meet your new requirements.
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);
It isn't pretty code, but it shows the direct way to get the job done.
Note: You have an error in your sample data table. You have a column name "Datd début 952" that needs to be changed to "Date début 952"
Jim
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Colonnes
I reworked the previous script to meet your new requirements.
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);
It isn't pretty code, but it shows the direct way to get the job done.
Note: You have an error in your sample data table. You have a column name "Datd début 952" that needs to be changed to "Date début 952"
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Colonnes
Merci cela fonctionne !
J’ai essayé de reprendre votre script mais au départ je savais pas comment caractériser toutes les colonnes du deuxième groupe car il n’y a pas de termes similaires.