code: def surprise_trainset_to_df(
      trainset, col_user="uid", col_item="iid", col_rating="rating"
  ):
      """Converts a `surprise.Trainset` object to `pandas.DataFrame`
  
      More info: https://surprise.readthedocs.io/en/stable/trainset.html
  
      Args:
          trainset (object): A surprise.Trainset object.
          col_user (str): User column name.
          col_item (str): Item column name.
          col_rating (str): Rating column name.
  
      Returns:
          pandas.DataFrame: A dataframe with user column (str), item column (str), and rating column (float).
      """
      df = pd.DataFrame(
          trainset.all_ratings(),
          columns=[col_user, col_item, col_rating],
      )
      map_user = (
          trainset._inner2raw_id_users
          if trainset._inner2raw_id_users is not None
          else invert_dictionary(trainset._raw2inner_id_users)
      )
      map_item = (
          trainset._inner2raw_id_items
          if trainset._inner2raw_id_items is not None
          else invert_dictionary(trainset._raw2inner_id_items)
      )
      df[col_user] = df[col_user].map(map_user)
      df[col_item] = df[col_item].map(map_item)
      return df
  
imports: import pandas
  import numpy
  from recommenders.utils.constants import DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_PREDICTION_COL
  from recommenders.utils.general_utils import invert_dictionary
label_desc: Use image node_id 1 for calling a global function with example usage: surprise_trainset_to_df(trainset, col_user, col_item, col_rating) and returns: df