code: def get_category_dispersion(
      corpus: TermDocMatrix,
      metric: str,
      corpus_to_parts: Optional[
          Callable[["TermDocMatrix"], List]
      ] = None,
      non_text: bool = False,
  ) -> pd.DataFrame:
      """
  
      :param corpus:  TermDocMatrix to process
      :param metric: a metric present in Dispersion.get_df. May be DA.
      :param corpus_to_parts: Optional function which takes a TermDocMatrix and returns a list of parts of each doc. None indicates each doc is a separate part.
      :param non_text: Use non text features. False by default
      :return: Dataframe giving category-specific features
      """
      data = {}
      for category in corpus.get_categories():
          category_corpus = corpus.remove_categories(
              [c for c in corpus.get_categories() if c != category]
          )
          if corpus_to_parts is not None:
              category_corpus = category_corpus.recategorize(
                  corpus_to_parts
              )
          dispersion_df = Dispersion(
              category_corpus,
              non_text=non_text,
              use_categories=corpus_to_parts is not None,
          ).get_df(include_da=metric == "DA")
          data[category + "_Frequency"] = dispersion_df.Frequency
          data[category + "_" + metric] = dispersion_df[metric]
      return pd.DataFrame(data).fillna(0)
  
imports: from typing import Optional, Callable, List
  import numpy
  import pandas
  from scattertext.termranking import AbsoluteFrequencyRanker
  from scipy.sparse import csc_matrix, csr_matrix
  from sklearn.preprocessing import StandardScaler
  from scattertext.smoothing.lowess import Lowess
  from scattertext.termranking.TermRanker import TermRanker
  from scattertext.TermDocMatrix import TermDocMatrix
label_desc: Use image node_id 1 for calling a global function with example usage: get_category_dispersion(corpus, metric, corpus_to_parts, non_text) and returns: pd