Is it right to impute Train and Test set? I am experimenting with a dataset and I have a couple of columns with high cardinality. So, I performed mean target encoding (given that my dataset had more than 50000 observations). But, before doing this, I split my data (using Pandas) into training and test and then encoded them. After checking, I realized that my training and testing datasets had Nan's. Since you can not run an ML algorithm with Nan's, I decided to impute both of them with MissForest.

My question is: Is what I have done acceptable?
Yes, it is possible to impute both the train and the test set. You have to be careful not to introduce information leakage by splitting - if you impute for the train set, then use the same imputation process for the test set as well. I believe that was mentioned in a comment as well. Here is some further information:

See https://stats.stackexchange.com/questions/95083/imputation-before-or-after-splitting-into-train-and-test