string to number

How to change the attribute from string to number in a way where one attribute is 1 and all the rest are 0?

Hi @Katrina_saba and welcome to the KNIME forum community

Could you please post here a snapshot and/or a text example of your source data with the result you would like to obtain ?

Thanks & regards,
Ael


I have this dataset in which I want to replace the airline name with value 0 except for Southwest Airlines to 1.

1 Like

Hi @Katrina_saba

This should do the trick:

$AIRLINE_NAME$ LIKE "*Southwest Airlines*" => 1

The above instruction with a “LIKE” allows a bit more of flexibility, for instance white characters before and after or other words.

If you are sure that “Southwest Airlines” is always written the same way then you could use instead:

$AIRLINE_NAME$ = "Southwest Airlines" => 1

Hope it helps.

best
Ael

4 Likes

In the classified value table, the attribute name changes to prediction rather than airline name as different from yours. How can I insert another column next to the airline name with the numerical value generated from this expression?

1 Like

As shown in the snapshot above, you can append a new column with the new values instead of reusing the column “AIRLINE_NAME”. It is up to you by selecting either option (append or replace).
As one can see too, the “I” in the right (highlighted too) means that the node has recognized that your new column is of type integer (I).

Hope it helps.
best
Ael

5 Likes

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