class_docstr: A class to store information about a feature, preprocess the data, and
  prepare summary statistics.
  
  Attributes
  ----------
  col_name : str or list of str
      The column name(s) of the feature in the input DataFrame.
  name : str
      The custom name of the feature.
  type : str
      The type of the feature, as determined by the _check_col function.
  cust_grid_points : array-like or list of arrays
      Custom grid points for the feature. For interact plot, it can also be a
      list of two arrays, indicating the grid points for each feature.
  grid_type : {'percentile', 'equal'}
      The grid type. Only applicable for numeric feature.
  num_grid_points : int or list of int
      The number of grid points to use. Only applicable for numeric feature. For
      interact plot, it can also be a list of two integers, indicating the number
      of grid points for each feature.
  percentile_range : tuple
      A tuple of two values indicating the range of percentiles to use. Only
      applicable for numeric feature and when `grid_type` is 'percentile'. If it
      is None, will use all samples.
  grid_range : tuple
      A tuple of two values indicating the range of grid values to use. Only
      applicable for numeric feature. If it is None, will use all samples.
  show_outliers : bool or list of bool
      Whether to show outliers in the plot. Only applicable for numeric feature.
      For interact plot, it can also be a list of two booleans, indicating
      whether to show outliers for each feature.
  endpoint : bool
      Whether to include the endpoint of the range.
  
  Methods
  -------
  prepare(**kwargs)
      Prepares the input DataFrame and calculates summary statistics.
class_docstr_tok: ["A","class","to","store","information","about","a","feature",",","preprocess","the","data",",","and","prepare","summary","statistics",".","Attributes","--","--","--","--","--","col_name",":","str","or","list","of","str","The","column","name","(","s",")","of","the","feature","in","the","input","DataFrame",".","name",":","str","The","custom","name","of","the","feature",".","type",":","str","The","type","of","the","feature",",","as","determined","by","the","_check_col","function",".","cust_grid_points",":","array-like","or","list","of","arrays","Custom","grid","points","for","the","feature",".","For","interact","plot",",","it","can","also","be","a","list","of","two","arrays",",","indicating","the","grid","points","for","each","feature",".","grid_type",":","{","'percentile","'",",","'equal","'","}","The","grid","type",".","Only","applicable","for","numeric","feature",".","num_grid_points",":","int","or","list","of","int","The","number","of","grid","points","to","use",".","Only","applicable","for","numeric","feature",".","For","interact","plot",",","it","can","also","be","a","list","of","two","integers",",","indicating","the","number","of","grid","points","for","each","feature",".","percentile_range",":","tuple","A","tuple","of","two","values","indicating","the","range","of","percentiles","to","use",".","Only","applicable","for","numeric","feature","and","when","`","grid_type","`","is","'percentile","'",".","If","it","is","None",",","will","use","all","samples",".","grid_range",":","tuple","A","tuple","of","two","values","indicating","the","range","of","grid","values","to","use",".","Only","applicable","for","numeric","feature",".","If","it","is","None",",","will","use","all","samples",".","show_outliers",":","bool","or","list","of","bool","Whether","to","show","outliers","in","the","plot",".","Only","applicable","for","numeric","feature",".","For","interact","plot",",","it","can","also","be","a","list","of","two","booleans",",","indicating","whether","to","show","outliers","for","each","feature",".","endpoint",":","bool","Whether","to","include","the","endpoint","of","the","range",".","Methods","--","--","--","-","prepare","(","*","*","kwargs",")","Prepares","the","input","DataFrame","and","calculates","summary","statistics","."]
docstr: Maps the values of the feature column to the appropriate bucket based
  on the grids attribute. Returns the input DataFrame with an additional
  column 'x' representing the bucket index for each value.
docstr_tok: ["Maps","the","values","of","the","feature","column","to","the","appropriate","bucket","based","on","the","grids","attribute",".","Returns","the","input","DataFrame","with","an","additional","column","'","x","'","representing","the","bucket","index","for","each","value","."]
code: def _map_values_to_buckets(self, df):
      """
      Maps the values of the feature column to the appropriate bucket based
      on the grids attribute. Returns the input DataFrame with an additional
      column 'x' representing the bucket index for each value.
      """
      col_name, grids = self.col_name, self.grids
      percentile_columns = []
  
      if self.type == "binary":
          df["x"] = df[col_name]
          display_columns = [f"{col_name}_{v}" for v in grids]
      elif self.type == "onehot":
          df["x"] = np.argmax(df[col_name].values, axis=1)
          df = df[~df["x"].isnull()].reset_index(drop=True)
          display_columns = list(grids)
      else:
          # map feature value into value buckets
          cut_result = pd.cut(
              df[self.col_name].values,
              bins=self.grids,
              right=False,
              precision=2,
          )
          df["x"] = cut_result.codes
          display_columns = [str(v) for v in cut_result.categories]
          # 1 ... 2 ... 3, index from 0
          x_max = len(self.grids) - 2
  
          if self.endpoint:
              df["x"] = df.apply(
                  lambda row: x_max
                  if row[self.col_name] == self.grids[-1]
                  else row["x"],
                  axis=1,
              )
              display_columns[-1] = display_columns[-1].replace(
                  ")", "]"
              )
  
          if self.grid_type == "percentile":
              for i, col in enumerate(display_columns):
                  per_vals = (
                      self.percentiles[i] + self.percentiles[i + 1]
                  )
                  per_min, per_max = str(min(per_vals)), str(
                      max(per_vals)
                  )
                  percentile_columns.append(
                      col[0] + ", ".join([per_min, per_max]) + col[-1]
                  )
  
          if self.show_outliers:
  
              def _assign_x(row):
                  if row["x"] != -1:
                      return row["x"]
                  if row[col_name] < grids[0]:
                      return -1
                  # if self.endpoint, grids[-1] is already assigned with x_max
                  if row[col_name] >= grids[-1]:
                      return x_max + 1
  
              df["x"] = df.apply(_assign_x, axis=1)
              if df["x"].min() == -1:
                  display_columns = [
                      "<" + str(self.grids[0])
                  ] + display_columns
  
                  if self.grid_type == "percentile":
                      percentile_columns = [
                          "<" + str(min(self.percentiles[0]))
                      ] + percentile_columns
  
              if df["x"].max() == x_max + 1:
                  display_columns += [
                      (">" if self.endpoint else ">=")
                      + str(self.grids[-1])
                  ]
                  if self.grid_type == "percentile":
                      percentile_columns += [
                          (">" if self.endpoint else ">=")
                          + str(max(self.percentiles[-1]))
                      ]
          else:
              df = df[df["x"] != -1]
  
          # offset results
          df["x"] -= df["x"].min()
  
      df["x"] = df["x"].map(int)
      self.display_columns = display_columns
      self.percentile_columns = percentile_columns
  
      return df
  
imports: import numpy
  import pandas
  import psutil
label_desc: Use image node_id 6 for calling the FeatureInfo obj's underlying member method code with example usage: obj._map_values_to_buckets(df) and returns: df, row, unknown, unknown