# Yes/No Encoding

**URL:** <https://forum.knime.com/t/yes-no-encoding/10366>\
**Category:** KNIME Analytics Platform\
**Created:** [March 21, 2018, 4:25am UTC](https://forum.knime.com/t/yes-no-encoding/10366 "2018-03-21T04:25:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabhpore444](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@saurabhpore444](https://forum.knime.com/u/saurabhpore444)\
**Post date:** [March 21, 2018, 4:25am UTC](https://forum.knime.com/t/yes-no-encoding/10366/1 "2018-03-21T04:25:20Z")

</div>

Hello,

I am graduate student and new to knime. I have dataset with more than 200k rows and 1k columns.

Some of the columns are Yes/No type questions. I want to encode Y --\> 1 and N --\> 0. I am using Category to Number node, but according to description “The category in the first row will be mapped to this value.” So, if two columns start with different category then the mapping is wrong. I want Y --\> 1 and N --\> 0 mapping every-time irrespective of the value in the first row.

---

<div class="post-metadata">

**Author:** ![moritz.heine](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@moritz.heine](https://forum.knime.com/u/moritz.heine)\
**Post date:** [March 21, 2018, 7:55am UTC](https://forum.knime.com/t/yes-no-encoding/10366/2 "2018-03-21T07:55:22Z")

</div>

Hello,

have a look at our Rule Engine Node, which is exactly what you are searching for.  
Simply create the two rules

$column name$ = “Y” =\> 1  
$column name$ = “N” =\> 0

This two rules guarantee that missing values are not matched to any of these values. If you want to match everything that is not a ‘Y’ or an ‘N’ to a third category simply add  
TRUE =\> 2 (or anything else)  
at the end of your rules.

Cheers,  
Moritz

---

<div class="post-metadata">

**Author:** ![saurabhpore444](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@saurabhpore444](https://forum.knime.com/u/saurabhpore444)\
**Post date:** [March 21, 2018, 2:40pm UTC](https://forum.knime.com/t/yes-no-encoding/10366/3 "2018-03-21T14:40:40Z")

</div>

Hello,

Thank You for the reply. But, there are more than 100 columns with this kind of data.

Is there a way to select multiple columns at the same time apply this rule.

---

<div class="post-metadata">

**Author:** ![moritz.heine](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@moritz.heine](https://forum.knime.com/u/moritz.heine)\
**Post date:** [March 21, 2018, 3:50pm UTC](https://forum.knime.com/t/yes-no-encoding/10366/4 "2018-03-21T15:50:21Z")

</div>

Hello,  
in this case you can use a Column List Loop Start and End (Column) Append Node and apply your rules inbetween. I’ve attached an example workflow.  
It splits the input table into two parts (in your case the columns containing the ‘Y’ and ‘N’ values, and the ones that don’t). Then it iterates over each column for which a specific rule shall be applied using the Column List Loop Start. Within this loop the column name is being extracted and the column name is replaced to a fix String, which we can use in the Rule Engine to apply our rule. After that the column is being renamed to the original one and appended using the End (Column) Append Node. After that the other columns are appended to this output table to retrieve the original input table with our replaced values.[Example.knwf](https://forum-cdn.knime.com/uploads/default/original/1X/a37ac3e87a1d65518c08ff12969ed40fbc87c866.knwf) (25.1 KB)

---

<div class="post-metadata">

**Author:** ![saurabhpore444](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@saurabhpore444](https://forum.knime.com/u/saurabhpore444)\
**Post date:** [March 22, 2018, 2:21pm UTC](https://forum.knime.com/t/yes-no-encoding/10366/5 "2018-03-22T14:21:01Z")

</div>

Thank You.

---

<div class="post-metadata">

**Author:** ![saurabhpore444](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@saurabhpore444](https://forum.knime.com/u/saurabhpore444)\
**Post date:** [April 28, 2018, 5:26pm UTC](https://forum.knime.com/t/yes-no-encoding/10366/6 "2018-04-28T17:26:07Z")

</div>

Hello,

With reference to Yes/No Encoding question, I found out way to use Category to Number node. But for that I have to use python script which adds row at the top containing all “N” values and after using Category to Number node I am again removing that row.

Is there another way doing the same ? Attached is the workflow and dataset.  
[YN.knwf](https://forum-cdn.knime.com/uploads/default/original/1X/3bc0b280c013e6121d043bae4d449bb8bdca66ea.knwf) (42.5 KB)  
[final\_5001 - Copy.xlsx](https://forum-cdn.knime.com/uploads/default/original/1X/850dd882dd78f913da04538bf6721629f0d1932d.xlsx) (1.9 MB)

---

<div class="post-metadata">

**Author:** ![Aaron\_Hart](https://forum-cdn.knime.com/user_avatar/forum.knime.com/aaron_hart/32/7814_2.png) [@Aaron\_Hart](https://forum.knime.com/u/Aaron_Hart)\
**Post date:** [May 8, 2018, 7:44am UTC](https://forum.knime.com/t/yes-no-encoding/10366/7 "2018-05-08T07:44:56Z")

</div>

Are you aware of the One to Many concept in KNIME? There are a series of nodes with variations on this name that deal with creating dummy variables/one hot encoding. Very handy!

---

<div class="post-metadata">

**Author:** ![Benedetta](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/c2a13f/32.png) [@Benedetta](https://forum.knime.com/u/Benedetta)\
**Post date:** [May 31, 2020, 4:53pm UTC](https://forum.knime.com/t/yes-no-encoding/10366/8 "2020-05-31T16:53:49Z")

</div>

Hi!  
I have to do the same action on more columns so i used the string manipulation node in a loop, exactley in the “column list loop start” and at the end “loop end(column append)” but it doesen’t work. When i replace the column name with “currentColumnName” in the Expression it doesn’t work. Can I have an example to understand how to use it?  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Iris](https://forum-cdn.knime.com/user_avatar/forum.knime.com/iris/32/14_2.png) [@Iris](https://forum.knime.com/u/Iris)\
**Post date:** [June 1, 2020, 8:42am UTC](https://forum.knime.com/t/yes-no-encoding/10366/9 "2020-06-01T08:42:16Z")

</div>

Hi @Benedetta

Please open a new topic for this. This one is quite outdated.

Best, Iris

---

<div class="post-metadata">

**Author:** ![Iris](https://forum-cdn.knime.com/user_avatar/forum.knime.com/iris/32/14_2.png) [@Iris](https://forum.knime.com/u/Iris)\
**Post date:** [June 1, 2020, 8:42am UTC](https://forum.knime.com/t/yes-no-encoding/10366/10 "2020-06-01T08:42:20Z")

</div>


