1
$\begingroup$

I have large number of categorical columns in my dataset, I want to preprocess the data, I know that I have to do one hot encoding but in data set columns or not in specific order they are at random positions. It will be difficult to do encoding for every column individually ... is there any solution to my problem if there what is it? I am using python

$\endgroup$
1
  • $\begingroup$ Just to check: Why are you sure that you want one-hot-encoding? Some down-stream uses are just fine with encoding as integers (e.g. for neural networks that turn the integer into an embedding, which one could then also use as inputs for other things), some could do well with some kind of target encoding etc. $\endgroup$
    – Björn
    Nov 26, 2021 at 14:53

1 Answer 1

0
$\begingroup$

It will be difficult to do encoding for every column individually ... is there any solution to my problem if there what is it? I am using python

You can use the get_dummies function in Pandas (http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.get_dummies.html). It only transforms columns of object type and leaves the floats and integer columns. Hence, you don't have to worry about specifying column indices explicitly, which is your concern, when I understood the part about the random order correctly.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.