The standard method to encode a categorical variable is one hot encoding. Replacing categories with numbers (ordinal encoding) would certainly introduce errors in the model because it would rely on numerical comparisons which are meaningless with categorical values.
The high number of dimensions can be a problem if the number of instances is too low and/or the variable has too many rare values. The risk is overfitting: the model would rely on values which happen by chance because it doesn't have
a large enough representative sample. In general the solution is to simplify the data: replace rare values (those which occur less than $n$ times in the training set) with a special value other
for example. Note that you can adjust the number of dimensions by varying the threshold $n$. It's very likely that there are many rare values and a smaller number of frequent values, therefore this method reduces the number of dimensions quickly. Note that the threshold $n$ can be determined by parameter tuning, but in this case you need a separate validation set (different from the final test set).
Note that you must always define the encoding using only the training data, then apply the predefined encoding on the test set. If the test set contains a value which doesn't exist in the training set, it should similarly be replaced with the special value other
.
[edit] Note that all of the above is very generic advice about the potential problems and possible solutions for this case. As usual, it depends a lot on the specifics of the task and data. The only way to find the optimal method is to experiment (Thanks to Sammy for reminding me to mention this).
sklearn
uses sparse matrix to store the large matrix created and helps optimally use computer memory. $\endgroup$