cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Fruit325
Level III

How to remove a user-defined text from all columns or all column names?

For example, I have a table:

 

Fruit325_0-1713802525393.png

1. All column names contain "CHA/", how could I remove it quickly and leave it like "Temp""Pressure" and "Flow"? In the real case, I have hundreds of columns containing "CHA/".

2. How could I make the first row as the column names? 

3. Is there any way to remove "CHA/" from all the cells in the table? 

 

Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How to remove a user-defined text from all columns or all column names?

1. You can use Recode Column Names to clean those

jthi_2-1713803596597.png

 

jthi_1-1713803577441.png

 

2. Top row to column names

jthi_0-1713803499897.png

3. Yes, either by scripting or using Search dialog and replace all

jthi_4-1713803665982.png

jthi_3-1713803625420.png

 

-Jarmo

View solution in original post

txnelson
Super User

Re: How to remove a user-defined text from all columns or all column names?

  1. @jthi provided a great interactive solution however, you may want to consider using a simple script that will change the column names that begin with CHA/ 
Names Default To Here( 1 );
dt = Current Data Table();

nameList = dt << get column names( string );

For Each( {col}, nameList, If( Starts With( col, "CHA/", Column( dt, col ) << set name( Substr( col, 5 ) ) ) ) );

2.

     1. If your data is input from a csv or txt file, you can use the input wizard to specify to use row 1 as the column headers.

     2. Or you can use a simple script to do the work.

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

nameList = dt << get column names( string );

For Each( {col}, nameList,
	column( dt, col) << set name( col[1] )
);

dt << delete rows(1);

3.  The search the columns for the value "CHA"

     1.  If the values are in what needs to be a numeric column, just by changing he column to be numeric will delete CHA from the cells in the column.

     2.  Or this simple script should do it

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

nameList = dt << get column names( string );

For Each( {col}, nameList,
	Try( Column( dt, col )[dt << get rows where( col == "CHA" )] = "" )
);
Jim

View solution in original post

4 REPLIES 4
jthi
Super User

Re: How to remove a user-defined text from all columns or all column names?

1. You can use Recode Column Names to clean those

jthi_2-1713803596597.png

 

jthi_1-1713803577441.png

 

2. Top row to column names

jthi_0-1713803499897.png

3. Yes, either by scripting or using Search dialog and replace all

jthi_4-1713803665982.png

jthi_3-1713803625420.png

 

-Jarmo
Fruit325
Level III

Re: How to remove a user-defined text from all columns or all column names?

Thank you! It worked and its very helpful! 

 

 

txnelson
Super User

Re: How to remove a user-defined text from all columns or all column names?

  1. @jthi provided a great interactive solution however, you may want to consider using a simple script that will change the column names that begin with CHA/ 
Names Default To Here( 1 );
dt = Current Data Table();

nameList = dt << get column names( string );

For Each( {col}, nameList, If( Starts With( col, "CHA/", Column( dt, col ) << set name( Substr( col, 5 ) ) ) ) );

2.

     1. If your data is input from a csv or txt file, you can use the input wizard to specify to use row 1 as the column headers.

     2. Or you can use a simple script to do the work.

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

nameList = dt << get column names( string );

For Each( {col}, nameList,
	column( dt, col) << set name( col[1] )
);

dt << delete rows(1);

3.  The search the columns for the value "CHA"

     1.  If the values are in what needs to be a numeric column, just by changing he column to be numeric will delete CHA from the cells in the column.

     2.  Or this simple script should do it

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

nameList = dt << get column names( string );

For Each( {col}, nameList,
	Try( Column( dt, col )[dt << get rows where( col == "CHA" )] = "" )
);
Jim
Fruit325
Level III

Re: How to remove a user-defined text from all columns or all column names?

Thank you!

I will try the script you show which is more flexible with more customized requirements.