code: def convert_index_format(
      df: Union[pd.DataFrame, pd.Series], level: str = "datetime"
  ) -> Union[pd.DataFrame, pd.Series]:
      """
      Convert the format of df.MultiIndex according to the following rules:
          - If `level` is the first level of df.MultiIndex, do nothing
          - If `level` is the second level of df.MultiIndex, swap the level of index.
  
      NOTE:
          the number of levels of df.MultiIndex should be 2
  
      Parameters
      ----------
      df : Union[pd.DataFrame, pd.Series]
          raw DataFrame/Series
      level : str, optional
          the level that will be converted to the first one, by default "datetime"
  
      Returns
      -------
      Union[pd.DataFrame, pd.Series]
          converted DataFrame/Series
      """
  
      if get_level_index(df, level=level) == 1:
          df = df.swaplevel().sort_index()
      return df
  
file_path: qlib/qlib/data/dataset/utils.py
imports: from __future__ import annotations
  import pandas
  from typing import Union, List, TYPE_CHECKING
  from qlib.utils import init_instance_by_config
label_desc: Use image node_id 4 for calling a global function with example usage: convert_index_format(df, level) and returns: df