Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Transform one categorical variable into a binary categorical variable

Karona
6 - Meteoroid

Hy,

 

I'm looking for a solution to transform one categorical variable into a binary categorical variable. The goal of this is to do an Association Analysis.

 

I know it's possible to create the variables manually but i search a macro which could do this for me.

 

My variable is the number of department and there are 99 possibilies in one categorical variable.

 

If you can avoid me do this manually, i will appriciate :)

 

Thanks for your help ! 

6 REPLIES 6
JohnJPS
15 - Aurora

Great question.  The attached macro should expand a given field into binary fields as you ask.  Be careful in using it though; if you have a lot of possible values in the "field to expand" it could result in an enormous number of columns.  You mentioned only having a hundred possible values, so for that problem this macro should work fine.

Capture.PNG

Hope that helps!

 - John

 

[EDIT: fixed to have False instead of Null values.]

JohnJPS
15 - Aurora

PS, an example simple workflow using the macro is attached here; (I tried attaching a .yxzp in the previous post but it didn't like the .yxzp for some reason).

 

Karona
6 - Meteoroid

Hy John ! Thanks for your help.

 

Unfortunately, i can't use your workflow because i don't have the last version of Alteryx. But i replicate the structure and modify  to include your solution in my workflow and it's works! Thanks again for your help.

 

Best regards.

JohnJPS
15 - Aurora

Glad to hear it worked. Aside: one tip/trick I've seen is that you can open a .yxmd or .yxmc in a text editor, and edit the first line to adjust the workflow/macro version. As long as it isn't using anything specific to the more recent version, that's an easy way to "roll back" the version.

mash
7 - Meteor

how would i modify this macro if I wanted to apply it to multiple categorical fields?

TimothyL
Alteryx Alumni (Retired)

@mash 

 

Just developed a one hot encoding in python here: https://gallery.alteryx.com/#!app/One-Hot-Encode-vPython/5caaef618a93370e4021a3ed

 

Give a try and let me know if any issue. TL

Labels