How to copy Month from Apr to May, from May to Jun ....

Hi I would like to add Month column like below.

Original
Column1 |
Apr |
1 |
2 |
3 |
May |
1 |
2 |
3 |

What I want to do is copying month till next month.
Column1 | Column2
Apr |Apr
1 |Apr
2 |Apr
3 |Apr
May |May
1 |May
2 |May
3 |May

Anybody knows how to do this? I would appreciate your help.

Hi @erisu,
Welcome to the KNIME Forum! You can use a Column Expressions node with the following code:

var month;
if (month && /[0-9]+/.test(column("column1"))) {
    month
} else {
    month = column("column1")    
}

Kind regards,
Alexander

3 Likes

Hi there @erisu,

welcome to KNIME Community!

I would use Rule Engine node first to create new column that will have month name in same row where month name is now and missing values (denoted in KNIME with red question mark) where numbers are. There are multiple ways to do it. Here are two. First with wildcards and second with regex:

NOT ($column1$ LIKE "?" OR $column1$ LIKE "??") => $column1$

$column1$ MATCHES "[a-zA-z]+" => $column1$

Note about Rule Engine node: “If no rule matches, the outcome is missing value.”

Then use Missing Value node with Previous value option :wink:

Br,
Ivan

4 Likes

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