BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
gallardet
Occasional Contributor

Delete all columns that have zeros in all raws

Well, that is what I need to do.

I tried to look for similar scripts but I have not found the solution.

Thanks in advance.

 

Manel

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Delete all columns that have zeros in all raws

Here is a simple script that will delete all columns that are all zeros

Names Default To Here( 1 );
dt = Current Data Table();

numericColNames = dt << get column names( string, numeric );

allZerosList = {};

For( i = 1, i <= N Items( numericColNames ), i++,
	If( Col Sum( Column( dt, numericColNames[i] ) ) == 0
	& Col Std Dev( Column( dt, numericColNames[i] ) ) == 0,
		Insert Into( allZerosList, numericColNames[i] )
	)
);

If( N Items( allZerosList ) > 0,
	dt << delete columns( allZerosList )
); 
Jim
3 REPLIES 3
ron_horne
Super User

Re: Delete all columns that have zeros in all raws

0 Kudos
txnelson
Super User

Re: Delete all columns that have zeros in all raws

Here is a simple script that will delete all columns that are all zeros

Names Default To Here( 1 );
dt = Current Data Table();

numericColNames = dt << get column names( string, numeric );

allZerosList = {};

For( i = 1, i <= N Items( numericColNames ), i++,
	If( Col Sum( Column( dt, numericColNames[i] ) ) == 0
	& Col Std Dev( Column( dt, numericColNames[i] ) ) == 0,
		Insert Into( allZerosList, numericColNames[i] )
	)
);

If( N Items( allZerosList ) > 0,
	dt << delete columns( allZerosList )
); 
Jim
gallardet
Occasional Contributor

Re: Delete all columns that have zeros in all raws

Thanks, Sir.
0 Kudos