code: def _prune_higher_ranked_terms(self, term_doc_matrix, rank_df, rank):
      terms_to_remove = rank_df.index[
          np.isnan(rank_df[rank_df <= rank]).apply(
              lambda x: all(x), axis=1
          )
      ]
      return self._remove_terms(term_doc_matrix, terms_to_remove)
  
imports: from typing import Optional, Tuple
  import pandas
  import numpy
  from scattertext.termscoring.CorpusBasedTermScorer import CorpusBasedTermScorer
  from scipy.stats import rankdata
  from scattertext.termranking.AbsoluteFrequencyRanker import AbsoluteFrequencyRanker
  from scattertext.termscoring.ScaledFScore import ScaledFScorePresetsNeg1To1
label_desc: Use image node_id 3 for calling the BaseAssociationCompactor obj's underlying member method code with example usage: obj._prune_higher_ranked_terms(term_doc_matrix, rank_df, rank) and returns: self