def transform(self, X):
    """
        Transforms columns of X specified in self.columns using
        LabelEncoder(). If no columns specified, transforms all
        columns in X.
        """
output = X.copy()
if self.columns is not None:
    for col in self.columns:
        output[col] = LabelEncoder().fit_transform(output[col])
else:
    for colname, col in output.items():
        output[colname] = LabelEncoder().fit_transform(col)
return output

def fit_transform(self, X, y=None):
    return self.fit(X, y).transform(X)
Кодировка меток в нескольких столбцах в scikit-learn