code: def from_nested_to_multi_index(
      X, instance_index=None, time_index=None
  ):
      """Convert nested pandas Panel to multi-index pandas Panel.
  
      Converts nested pandas DataFrame (with time series as pandas Series
      or NumPy array in cells) into multi-indexed pandas DataFrame.
  
      Can convert mixed nested and primitive DataFrame to multi-index DataFrame.
  
      Parameters
      ----------
      X : pd.DataFrame
          The nested DataFrame to convert to a multi-indexed pandas DataFrame
  
      instance_index : str
          Name of the multi-index level corresponding to the DataFrame's instances
  
      time_index : str
          Name of multi-index level corresponding to DataFrame's timepoints
  
      Returns
      -------
      X_mi : pd.DataFrame
          The multi-indexed pandas DataFrame
      """
      # this contains the right values, but does not have the right index
      #   need convert_dtypes or dtypes will always be object
      # explode by column to ensure we deal with unequal length series properly
      X_mi = pd.DataFrame()
  
      X_cols = X.columns
      nested_cols = [
          c for c in X_cols if isinstance(X[[c]].iloc[0, 0], pd.Series)
      ]
      non_nested_cols = list(set(X_cols).difference(nested_cols))
  
      for c in nested_cols:
          X_col = X[[c]].explode(c)
          X_col = X_col.infer_objects()
  
          # create the right MultiIndex and assign to X_mi
          idx_df = df_map(X[[c]])(lambda x: x.index).explode(c)
          index = pd.MultiIndex.from_arrays(
              [idx_df.index, idx_df[c].values]
          )
          index = index.set_names([instance_index, time_index])
          X_col.index = index
  
          X_mi[[c]] = X_col
  
      for c in non_nested_cols:
          for ix in X.index:
              X_mi.loc[ix, c] = X[[c]].loc[ix].iloc[0]
          X_mi[[c]] = X_mi[[c]].convert_dtypes()
  
      return X_mi
  
imports: import numpy
  import pandas
  from sktime.datatypes._convert_utils._coerce import _coerce_df_dtypes
  from sktime.datatypes._convert_utils._convert import _extend_conversions
  from sktime.datatypes._panel._registry import MTYPE_LIST_PANEL
  from sktime.utils.pandas import df_map
  from sktime.utils.validation._dependencies import _check_soft_dependencies
label_desc: Use image node_id 33 for calling a global function with example usage: from_nested_to_multi_index(X, instance_index, time_index) and returns: X_mi