Replace column name IF...

Hello there,

Yesterday I had uploaded a .csv and funny characters where in there, ie: í>>?“”" so I set a column rename and continued the workflow.

Today I have entered a new .csv file and the funny characters are gone only to find Column0.

I would like to check that column name, for something specific, for example:
if its name is NOT ‘color’, then rename it to ‘car’, if it’s ‘car’ obviously do nothing.

How can I accomplish this? My workflow now has a column w a different name. I am afraid if I fix this column now, next time I add a new file, the funny characters will be there again then I have to redo the node conditions every time.

Thanks a lot!
J.

Hi @jarviscampbell

Another user recently experienced something similar. The Column Rename (Regex) is a way to tackle this problem:

With the example that you mentioned, you can use ^(?!.*color).*$ as Regex term and replace it with ‘’‘car’
Dummy input:
image

Column Rename Regex

image
Note: KNIME automatically adds sequential numbers for columns equally named.

For the special characters cleansing, it’s even easier. If you know which chars you expected in your columns, you can clean-up anything that does not meet those requirements.

For example with these headers:
image

Let’s assume that your columns normally only contains letters and numbers, you can use [^A-Za-z0-9] and replace it with a blank or a character of your choice.

Hope this helps!

Edit: If you double stack the above steps and also what @bruno29a rightly points out here then you definitely won’t encounter this issue anymore :wink:

5 Likes

Thanks @ArjenEX , I will try the UTF-8 trick next time, although I have a feeling it already has it set that way.

I have not yet tried your solution. Just wanted to check in and let you know I see your reply and will try this week. I appreciate your answer.

J.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.