code: def get_xgboost_path_df(xgbmodel, X_row, n_tree=None):
      """returns a pd.DataFrame of the prediction path through
      an individual tree in a xgboost ensemble.
  
      Args:
          xgbmodel: either a fitted xgboost model, or the output of a get_dump()
          X_row: single row from a dataframe (e.g. X_test.iloc[0])
          n_tree: the tree number to display:
  
      Returns:
          pd.DataFrame
      """
      if isinstance(xgbmodel, str) and xgbmodel.startswith("0:"):
          xgbmodel_treedump = xgbmodel
      elif str(type(xgbmodel)).endswith("xgboost.core.Booster'>"):
          xgbmodel_treedump = xgbmodel.get_dump()[n_tree]
      elif str(type(xgbmodel)).endswith("XGBClassifier'>") or str(
          type(xgbmodel)
      ).endswith("XGBRegressor'>"):
          xgbmodel_treedump = xgbmodel.get_booster().get_dump()[n_tree]
      else:
          raise ValueError(
              "Couldn't extract a treedump. Please pass a fitted xgboost model."
          )
      if isinstance(X_row, pd.DataFrame) and len(X_row) == 1:
          X_row = X_row.squeeze()
      node_dict = get_xgboost_node_dict(xgbmodel_treedump)
  
      prediction_path_df = pd.DataFrame(
          columns=["node", "feature", "cutoff", "value"]
      )
  
      node = node_dict[0]
      while not node["is_leaf"]:
          prediction_path_df = append_dict_to_df(
              prediction_path_df,
              dict(
                  node=node["node"],
                  feature=node["feature"],
                  cutoff=node["cutoff"],
                  value=float(X_row[node["feature"]]),
              ),
          )
          if (
              np.isnan(X_row[node["feature"]])
              or X_row[node["feature"]] < node["cutoff"]
          ):
              node = node_dict[node["left_node"]]
          else:
              node = node_dict[node["right_node"]]
  
      if node["is_leaf"]:
          prediction_path_df = append_dict_to_df(
              prediction_path_df,
              dict(
                  node=node["node"],
                  feature="_PREDICTION",
                  value=node["leaf_value"],
              ),
          )
      return prediction_path_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 30 for calling a global function with example usage: get_xgboost_path_df(xgbmodel, X_row, n_tree) and returns: prediction_path_df