code: def normalize_graph(
      g: Plottable, self_edges: bool = False, unwrap: bool = False
  ) -> Plottable:
      """Final step after collapse traversals are done, removes duplicates and moves COLLAPSE columns into respective(node, src, dst) columns of node, edges dataframe from Graphistry instance g.
  
      :param g: graphistry instance
      :param self_edges: bool, whether to keep duplicates from ndf, edf, default False
      :param unwrap: bool, whether to unwrap node text with `~`, default True
  
      :returns: final graphistry instance
      """
  
      ndf, edf, src, dst, node = unpack(g)
  
      # we set src and COLLAPSE to FINAL so that we can run algo idempotently and in chain without having to know new node ids
      # move the new node names from COLLAPSE COL to the FINAL COLS
      ndf.loc[ndf[COLLAPSE_NODE] != DEFAULT_VAL, FINAL_NODE] = ndf.loc[
          ndf[COLLAPSE_NODE] != DEFAULT_VAL, COLLAPSE_NODE
      ]
      # set the untouched nodes to FINAL
      ndf.loc[ndf[COLLAPSE_NODE] == DEFAULT_VAL, FINAL_NODE] = ndf.loc[
          ndf[COLLAPSE_NODE] == DEFAULT_VAL, node
      ]
      ndf = ndf.drop_duplicates()
  
      # set the new data in FINAL edges
      edf.loc[edf[COLLAPSE_SRC] != DEFAULT_VAL, FINAL_SRC] = edf.loc[
          edf[COLLAPSE_SRC] != DEFAULT_VAL, COLLAPSE_SRC
      ]
      edf.loc[edf[COLLAPSE_DST] != DEFAULT_VAL, FINAL_DST] = edf.loc[
          edf[COLLAPSE_DST] != DEFAULT_VAL, COLLAPSE_DST
      ]
      # set the old data in FINAL edges
      edf.loc[edf[COLLAPSE_SRC] == DEFAULT_VAL, FINAL_SRC] = edf.loc[
          edf[COLLAPSE_SRC] == DEFAULT_VAL, src
      ]
      edf.loc[edf[COLLAPSE_DST] == DEFAULT_VAL, FINAL_DST] = edf.loc[
          edf[COLLAPSE_DST] == DEFAULT_VAL, dst
      ]
  
      if not self_edges:
          edf = edf.drop_duplicates()
  
      if unwrap:  # this is only to make things more readable.
          ndf[FINAL_NODE] = (
              ndf[FINAL_NODE].astype(str).apply(lambda x: unwrap_key(x))
          )
          edf[FINAL_SRC] = (
              edf[FINAL_SRC].astype(str).apply(lambda x: unwrap_key(x))
          )
          edf[FINAL_DST] = (
              edf[FINAL_DST].astype(str).apply(lambda x: unwrap_key(x))
          )
  
      # set the dataframes according to FINAL nodes
      g._nodes = ndf
      g._edges = edf
      g._node = FINAL_NODE
      g._source = FINAL_SRC
      g._destination = FINAL_DST
      return g
  
imports: from typing import Union, Optional, List
  import copy, logging, pandas, numpy
  from graphistry.PlotterBase import Plottable
label_desc: Use image node_id 18 for calling a global function with example usage: normalize_graph(g, _edges, unwrap) and returns: g