docstr: Transform categorical data based on mapping learnt at fitting time.
  
  :param pandas.DataFrame X: DataFrame of features, shape (n_samples, n_features). Must contain columns to encode.
  :return: encoded DataFrame of shape (n_samples, n_features), initial categorical columns are dropped, and
      replaced with encoded columns. DataFrame passed in argument is unchanged.
  :rtype: pandas.DataFrame
docstr_tok: ["Transform","categorical","data","based","on","mapping","learnt","at","fitting","time",".",":","param","pandas.DataFrame","X",":","DataFrame","of","features",",","shape","(","n_samples",",","n_features",")",".","Must","contain","columns","to","encode",".",":","return",":","encoded","DataFrame","of","shape","(","n_samples",",","n_features",")",",","initial","categorical","columns","are","dropped",",","and","replaced","with","encoded","columns",".","DataFrame","passed","in","argument","is","unchanged",".",":","rtype",":","pandas.DataFrame"]
code: def transform(self, X):
      """Transform categorical data based on mapping learnt at fitting time.
  
      :param pandas.DataFrame X: DataFrame of features, shape (n_samples, n_features). Must contain columns to encode.
      :return: encoded DataFrame of shape (n_samples, n_features), initial categorical columns are dropped, and
          replaced with encoded columns. DataFrame passed in argument is unchanged.
      :rtype: pandas.DataFrame
      """
      if not self._mapping:
          raise ValueError(
              "`fit` method must be called before `transform`."
          )
      assert all(c in X.columns for c in self.cols)
      if self.handle_missing == "error":
          assert (
              not X[self.cols].isnull().any().any()
          ), "`handle_missing` = `error` and missing values found in columns to encode."
      X_encoded = X.copy(deep=True)
      for col, mapping in self._mapping.items():
          X_encoded[col] = (
              X_encoded[col].fillna(NAN_CATEGORY).map(mapping["value"])
          )
  
          if self.handle_unseen == "impute":
              X_encoded[col].fillna(self._imputed, inplace=True)
          elif self.handle_unseen == "error":
              if np.unique(X_encoded[col]).shape[0] > mapping.shape[0]:
                  raise ValueError(
                      f"Unseen categories found in `{col}` column."
                  )
  
      return X_encoded
  
imports: from pandas import DataFrame, Series, unique
  import numpy
  from rich.progress import track
  from sklearn.base import BaseEstimator, TransformerMixin
  from pytorch_tabular.utils import get_logger
label_desc: Use image node_id 2 for calling the BaseEncoder obj's underlying member method code with example usage: obj.transform(X) and returns: X_encoded