Replace specific rows values considering the value condition of another column

Hello,
I have a data table like the example below:

user_id value_1
1 new york
2 wrong value
3 cuba
4 paris
5 wrong value
6 wrong value

I know that the correct values to replace the wrong value rows in value_1 column are:

  • Amsterdam for user_id=2
  • Sidney for user_id=5
  • Singapore for user_id=6

So, my question is: how can I replace specific values based on specific column value condtion?
Which is the faster solution to the problem? Maybe a sort of if statement? Maybe should I use a dictionary made of the correct values to replace?

Thanks in advance.

Attached is one way to do it, Yes I would use a table with the correct values. You cloud also write code in a Rule Engine or a Java Snippet but then if you would want to edit something you would have to go thru a lot of code.

54

example_wrong_city.knwf (21.7 KB)

2 Likes

Use your correct values as the second input to a Joiner, do left outer join joining on id, then you should have correct values in a new column with missing values where the original was correct.

Now use a column merger node (https://nodepit.com/node/org.knime.base.node.preproc.columnmerge.ColumnMergerNodeFactory) with the corrected values as primary column and original as secondary, selecting option to replace both columns.

Steve

1 Like

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