code: def from_2d_array_to_nested(
      X, index=None, columns=None, time_index=None, cells_as_numpy=False
  ):
      """Convert 2D dataframe to nested dataframe.
  
      Convert tabular pandas DataFrame with only primitives in cells into
      nested pandas DataFrame with a single column.
  
      Parameters
      ----------
      X : pd.DataFrame
  
      cells_as_numpy : bool, default = False
          If True, then nested cells contain NumPy array
          If False, then nested cells contain pandas Series
  
      index : array-like, shape=[n_samples], optional (default = None)
          Sample (row) index of transformed DataFrame
  
      time_index : array-like, shape=[n_obs], optional (default = None)
          Time series index of transformed DataFrame
  
      Returns
      -------
      Xt : pd.DataFrame
          Transformed DataFrame in nested format
      """
      if (time_index is not None) and cells_as_numpy:
          raise ValueError(
              "`Time_index` cannot be specified when `return_arrays` is True, "
              "time index can only be set to "
              "pandas Series"
          )
      if isinstance(X, pd.DataFrame):
          X = X.to_numpy()
  
      container = np.array if cells_as_numpy else pd.Series
  
      # for 2d numpy array, rows represent instances, columns represent time points
      n_instances, n_timepoints = X.shape
  
      if time_index is None:
          time_index = np.arange(n_timepoints)
      kwargs = {"index": time_index}
  
      Xt = pd.DataFrame(
          pd.Series(
              [container(X[i, :], **kwargs) for i in range(n_instances)]
          )
      )
      if index is not None:
          Xt.index = index
      if columns is not None:
          Xt.columns = columns
      return Xt
  
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 13 for calling a global function with example usage: from_2d_array_to_nested(X, index, columns, time_index, cells_as_numpy) and returns: Xt