split data such that a a categorical value is either in train or test python

I have a data set (df) as follows Company Col1 Col2 Output AB 10 20 1 AB 20 22 1 AB 14 12 0 XZ 33 22 1 XZ 43 62 0 I want to train_test_split the data such that if a company is in the test set, it should not be in the training… Read More split data such that a a categorical value is either in train or test python