code: def to_ts_dataframe(
      df: pd.DataFrame, time_col=None
  ) -> (pd.DataFrame, str):
      columns = list(df.columns.values)
      # if time column has been specified, check the specified time column
      if time_col is not None:
          if time_col not in columns:
              raise Exception("invalid column name: " + time_col)
          if df[time_col].dtype != np.datetime64:
              try:
                  idx = pd.to_datetime(df[time_col])
              except Exception as e:
                  raise Exception(
                      "can not convert column to datetime: "
                      + time_col
                      + " "
                      + str(e)
                  )
      # if time column has not been specified, try to find one
      else:
          datetime_cols = list(
              df.select_dtypes(include=["datetime"]).columns.values
          )
          if len(datetime_cols) > 0:
              time_col = datetime_cols[0]
              idx = pd.to_datetime(df[time_col])
          else:
              raise Exception(
                  "can not find datetime column for time series"
              )
      # build return dataframe
      rt_df = copy.deepcopy(df)
      rt_df.drop(columns=[time_col], inplace=True)
      rt_df.index = idx
      return rt_df, time_col
  
imports: from enum import Enum
  import json
  from typing import Optional, Dict
  import numpy
  import pandas
  import copy
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.utilities import log
  from .adapters import BaseMerlionForecastAdapter, DefaultForecasterAdapter, MerlionArguments, DefaultDetectorAdapter, SarimaForecasterAdapter, ProphetForecasterAdapter, MSESForecasterAdapter, IsolationForestDetectorAdapter, WindStatsDetectorAdapter, ProphetDetectorAdapter
label_desc: Use image node_id 3 for calling a global function with example usage: to_ts_dataframe(df, time_col) and returns: rt_df,  time_col