Converting nominal variables and ordinal variables in dataframe - categorical variables I have a data frame in which I have some categorical variables, some are ordinal and others
are nominal.
How can I deal with nominal columns/variables that have too many levels?
For example, I have a column native_country which would be a nominal variable.
Is there a way of converting such columns like the one mentioned above the way we do it
with ordinal variables? Meaning that, when I am converting for ordinal columns you can have only one column for all levels each one having its unique number. But for nominal variables, different methods generate one column per level.
I am working with python and skit-learn library, so for now I decided to use OrdinalEncoder for
ordinal columns, and OneHotEncoder for nominal columns.
The link to the dataset: https://www.kaggle.com/datasets/uciml/adult-census-income

So basically, your're dealing with unordered categories of high cardinality. Is some information loss acceptable?
If yes, you may use feature hashing or bitstrings. Otherwise leave one out variety of mean target encoding is the default choice. There are other options, like weight of evidence, but you should be cautious about the target leakage.
Most of the advanced encoding algorithms are implemented by the category_encoders library (nicely compatible with sklearn).
There's also a nice encoding method selection flowchart with several info links.
