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

Besides the options listed by @dx2-66 in their answer, it may be quite useful to use related external data if you can, depending on the problem you're trying to solve.
For example, if you want to convert native_country to a quantitative variable, you could use the GDP per capita of this country, instead of its name. Or if you want to stick to categorical variables for some reason, you could convert the country name to the World Bank category it belongs to -it will reduce drastically the number of categories you have.
There is a boatload of indicators you could consider using, see https://en.wikipedia.org/wiki/List_of_international_rankings for a non-exhaustive list.  Beware, many international ranking indicators are associated to the GDP, so confounding is a risk to consider when you choose some indicator(s) to replace your categorical variable. Choosing the right indicator(s) may be a matter of domain expertise, not just a purely statistical problem.
