code: def merge_importance_dfs(
      df_old: pd.DataFrame,
      df_new: pd.DataFrame,
      using_prev_fit_fi: Set[str],
  ) -> pd.DataFrame:
      """
      Create a dataframe that correctly merges two existing dataframe's permutation feature importance statistics,
      specifically mean, standard deviation, and shuffle count. For each feature, if one dataframe's feature importance
      has not been calculated, the resulting dataframe will contain the other dataframe's feature importance stats.
      df_old is assumed to have been from previous feature importance computation round or even pruning round and
      can have more features (rows) than df_new. Also, update using_prev_fit_fi to indicate the updated feature list that
      uses feature importance values from previous fit.
      """
      if df_old is None:
          # Remove features whose importance has just been computed from using_prev_fit_fi if they exist
          using_prev_fit_fi.difference_update(
              df_new[df_new["n"] > 0].index.tolist()
          )
          return df_new
      assert len(df_old) >= len(
          df_new
      ), "df_old cannot have less rows than df_new."
      evaluated_old_rows, evaluated_new_rows = (
          df_old[df_old["n"] > 0],
          df_new[df_new["n"] > 0],
      )
      unevaluated_old_rows, unevaluated_new_rows = (
          df_old[df_old["n"] == 0],
          df_new[df_new["n"] == 0],
      )
      evaluated_both = (
          evaluated_new_rows.index.intersection(
              evaluated_old_rows.index
          )
          .difference(using_prev_fit_fi)
          .tolist()
      )
      evaluated_neither = unevaluated_new_rows.index.intersection(
          unevaluated_old_rows.index
      ).tolist()
      evaluated_old_only = evaluated_old_rows[
          evaluated_old_rows.index.isin(unevaluated_new_rows.index)
      ].index.tolist()
      evaluated_new_only = evaluated_new_rows[
          evaluated_new_rows.index.isin(unevaluated_old_rows.index)
      ].index.tolist()
      evaluated_new_first_time = evaluated_new_rows.index.intersection(
          using_prev_fit_fi
      ).tolist()
  
      # for features with no info on both df_old and df_new, return no info rows
      evaluated_neither_rows = unevaluated_new_rows.loc[
          evaluated_neither
      ]
      # for features with info on only df_old, return corresponding df_old rows
      evaluated_old_only_rows = evaluated_old_rows.loc[
          evaluated_old_only
      ]
      # for features with info on only df_new or whose df_old feature importance came from the previous model, return corresponding df_new rows
      evaluated_new_only_rows = evaluated_new_rows.loc[
          list(set(evaluated_new_only + evaluated_new_first_time))
      ]
      # for features with info on both df_new and whose df_old feature importance came from the current model, return combined statistics
      evaluated_both_rows = pd.DataFrame()
      evaluated_both_rows_new = evaluated_new_rows.loc[
          evaluated_both
      ].sort_index()
      evaluated_both_rows_old = evaluated_old_rows.loc[
          evaluated_both
      ].sort_index()
      mean_old, mean_new = (
          evaluated_both_rows_old["importance"],
          evaluated_both_rows_new["importance"],
      )
      stddev_old, stddev_new = (
          evaluated_both_rows_old["stddev"],
          evaluated_both_rows_new["stddev"],
      )
      n_old, n_new = (
          evaluated_both_rows_old["n"],
          evaluated_both_rows_new["n"],
      )
      evaluated_both_rows["importance"] = (
          n_old * mean_old + n_new * mean_new
      ) / (n_old + n_new)
      # Refer to https://math.stackexchange.com/questions/2971315/how-do-i-combine-standard-deviations-of-two-groups
      evaluated_both_rows["stddev"] = (
          (
              (n_old - 1) * stddev_old**2
              + (n_new - 1) * stddev_new**2
          )
          / (n_old + n_new - 1)
          + (n_old * n_new * (mean_old - mean_new) ** 2)
          / ((n_old + n_new) * (n_old + n_new - 1))
      ) ** 0.5
      evaluated_both_rows["p_value"] = None
      evaluated_both_rows["n"] = n_old + n_new
      # remove features evaluated in df_new from using_prev_fit_fi if they exist
      using_prev_fit_fi.difference_update(
          evaluated_new_rows.index.tolist()
      )
      result = pd.concat(
          [
              evaluated_both_rows,
              evaluated_new_only_rows,
              evaluated_old_only_rows,
              evaluated_neither_rows,
          ]
      ).sort_values("importance")
      assert len(result) == len(
          df_new
      ), "Length of the updated DataFrame must be equal to the inputted DataFrame."
      return result
  
imports: import logging
  import time
  import traceback
  import uuid
  from copy import deepcopy
  from typing import List, Set, Tuple, Union
  import numpy
  import pandas
  from autogluon.common.features.types import R_FLOAT
  from ..models.abstract.abstract_model import AbstractModel
  from ..models.ensemble.bagged_ensemble_model import BaggedEnsembleModel
  from ..utils.exceptions import TimeLimitExceeded
  from ..utils.utils import generate_train_test_split, unevaluated_fi_df_template
label_desc: Use image node_id 2 for calling a global function with example usage: merge_importance_dfs(df_old, df_new, using_prev_fit_fi) and returns: result, df_new