code: def get_pdp_df(
      model,
      X_sample: pd.DataFrame,
      feature: Union[str, List],
      pos_label=1,
      n_grid_points: int = 10,
      min_percentage: int = 0,
      max_percentage: int = 100,
      multiclass: bool = False,
      grid_values: List = None,
      is_classifier: bool = False,
      cast_to_float32: bool = False,
  ):
      """Returns a dataframe with partial dependence for every row in X_sample for a number of feature values
  
      Args:
          model (): sklearn compatible model to generate pdp for
          X_sample (pd.DataFrame): X to generate pdp for
          feature (Union[str, List]): Feature to generate pdp for. Either the
              name of a column in X_sample, or a list of onehot-encoded columns.
          pos_label (int, optional): for classifier model, which class to use
              as the positive class. Defaults to 1.
          n_grid_points (int, optional): For numeric features: number of grid points
              to divide the x axis by. Defaults to 10.
          min_percentage (int, optional): For numeric features: minimum percentage of
              samples to start x axis by. If large than 0 a form of winsorizing the
              x axis. Defaults to 0.
          max_percentage (int, optional): For numeric features: maximum percentage of
              samples to end x axis by. If smaller than 100 a form of winsorizing the
              x axis. Defaults to 100.
          multiclass (bool, optional): for classifier models, return a list of dataframes,
              one for each predicted label.
          grid_values (list, optional): list of grid values. Default to None, in which
              case it will be inferred from X_sample.
          is_classifier (bool, optional): model is a classifier with a pred_probas method.
          cast_to_float32 (bool, optional): cast model input to np.float32 (necessary for
              skorch models)
      """
  
      if grid_values is None:
          if isinstance(feature, str):
              if not is_numeric_dtype(X_sample[feature]):
                  grid_values = sorted(
                      X_sample[feature].unique().tolist()
                  )
              else:
                  grid_values = get_grid_points(
                      X_sample[feature],
                      n_grid_points=n_grid_points,
                      min_percentage=min_percentage,
                      max_percentage=max_percentage,
                  ).tolist()
          elif isinstance(feature, list):
              grid_values = feature
          else:
              raise ValueError(
                  "feature should either be a column name (str), "
                  "or a list of onehot-encoded columns!"
              )
  
      if is_classifier:
          if cast_to_float32:
              first_row = X_sample.iloc[[0]].values.astype("float32")
          else:
              first_row = X_sample.iloc[[0]]
          warnings.filterwarnings("ignore", category=UserWarning)
          n_labels = model.predict_proba(first_row).shape[1]
          warnings.filterwarnings("default", category=UserWarning)
          if multiclass:
              pdp_dfs = [pd.DataFrame() for i in range(n_labels)]
          else:
              pdp_df = pd.DataFrame()
      else:
          pdp_df = pd.DataFrame()
      for grid_value in grid_values:
          dtemp = X_sample.copy()
          if isinstance(feature, list):
              if grid_value in X_sample.columns:
                  assert set(X_sample[grid_value].unique()).issubset(
                      {0, 1}
                  ), (
                      f"{grid_values} When passing a list of features these have to be onehotencoded!"
                      f"But X_sample['{grid_value}'].unique()=={list(set(X_sample[grid_value].unique()))}"
                  )
              dtemp.loc[:, feature] = [
                  1 if col == grid_value else 0 for col in feature
              ]
          else:
              dtemp[[feature]] = grid_value
          if is_classifier:
              if cast_to_float32:
                  dtemp = dtemp.values.astype("float32")
              pred_probas = model.predict_proba(dtemp).squeeze()
              if multiclass:
                  for i in range(n_labels):
                      pdp_dfs[i][grid_value] = pred_probas[:, i]
              else:
                  pdp_df[grid_value] = pred_probas[:, pos_label]
          else:
              if cast_to_float32:
                  dtemp = dtemp.values.astype("float32")
              preds = model.predict(dtemp).squeeze()
              pdp_df[grid_value] = preds
      if multiclass:
          return pdp_dfs
      else:
          return pdp_df
  
imports: from functools import partial
  import re
  from collections import Counter
  from typing import List, Union
  import warnings
  import numpy
  import pandas
  from pandas.api.types import is_numeric_dtype, is_categorical_dtype
  from dtreeviz.trees import ShadowDecTree
  from sklearn.metrics import make_scorer
  from sklearn.base import clone
  from sklearn.pipeline import Pipeline
  from sklearn.model_selection import KFold, StratifiedKFold
  from joblib import Parallel, delayed
label_desc: Use image node_id 21 for calling a global function with example usage: get_pdp_df(model, X_sample, feature, pos_label, n_grid_points, min_percentage, max_percentage, multiclass, grid_values, is_classifier, cast_to_float32) and returns: pdp_dfs, pdp_df