How to rename a column originally named as the current month?

#1

Hi, I need to rename a column with x name using Column Rename node, however the column’s original name will change each month. So for example this month the column I need to rename will be named DEC 2018, but next month it’s going to be JAN 2019.

I tried getting the current date as a variable using Date&Time Input and String Manipulation nodes but I don’t know how to rename the column that has the same name as the variable.

Thanks in advance.

0 Likes

#2

Hi @_Aura_C2 -

Here’s one way you could do it.

2018-12-12%2015_36_53-KNIME%20Analytics%20Platform

RenameColumnCurrentDate.knwf (14.8 KB)

0 Likes

#3

Hi @ScottF,

Thanks for the workflow but not quite what I need. You are renaming a column (NewCol) with the name in the variable, and I need to do the opposite that would be rename a column that already has the dynamic date as header (DEC 2018 --> rename --> NewCol) considering that the date (input column) will be different each month.

0 Likes

#4

Most likely your monthly column has same order place. So, using Column Expression node you can address column by number. Also, you can extract and assign header to the table using Extract Column Header and Insert Column Header nodes.

0 Likes

#5

What about a Column Rename (regex) node? The regex could be something like:
(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC) 20[0-9][0-9]
…including brackets and spaces.
(Cannot test it at the moment because i am on mobile, let me know if it doesnt work)

0 Likes

#6

Thanks this might be a good option I will try it!

0 Likes