I have a number of columns in my table which have text values that fall into categories - e.g. column "ABC" has 9000 rows but every row must have a value in the set {"A","B","C"}. Other columns like Gender have "M"/"F"/null
For each column, I'd like to convert it into an integer list in-place - so A:1, B:2, C:3 etc.
I've been trying out using List.Distinct
to extract the values to a temp table, adding an index column to that and using a join to transform the initial column based on that mapping in the temp table. However this seems slow and I'm not sure how to run this over all columns in my table (or at least Table.ColumnsOfType(Source, {type nullable text})
to select the categorical columns...).
Any suggestions?
Before
Gender | Fruit | [...] |
---|---|---|
F | Cat | |
F | Dog | |
M | Lemon | |
M | Dog | |
M | Lemon | |
null | Cat | |
M | Dog |
After
Gender | Fruit | [...] |
---|---|---|
1 | 1 | |
1 | 2 | |
2 | 3 | |
2 | 2 | |
2 | 3 | |
null | 1 | |
2 | 2 |