code: def convert_to_data(val, keep_index=False):
      if isinstance(val, Data):
          return val
      if isinstance(val, np.ndarray):
          return DenseData(val, [str(i) for i in range(val.shape[1])])
      if isinstance(val, pd.Series):
          return DenseData(
              val.values.reshape((1, len(val))), list(val.index)
          )
      if isinstance(val, pd.DataFrame):
          if keep_index:
              return DenseDataWithIndex(
                  val.values,
                  list(val.columns),
                  val.index.values,
                  val.index.name,
              )
          else:
              return DenseData(val.values, list(val.columns))
      if scipy.sparse.issparse(val):
          if not scipy.sparse.isspmatrix_csr(val):
              val = val.tocsr()
          return SparseData(val)
  
      emsg = f"Unknown type passed as data object: {type(val)}"
      raise TypeError(emsg)
  
imports: import copy
  import numpy
  import pandas
  import scipy.sparse
  from sklearn.cluster import KMeans
  from sklearn.impute import SimpleImputer
label_desc: Use image node_id 7 for calling a global function with example usage: convert_to_data(val, keep_index) and returns: val, DenseData, DenseData, SparseData, DenseDataWithIndex, DenseData