class_docstr: This class allows you to produce scatter plots of raw term frequency counts.
  
  Occasionally, only term frequency statistics are available. This may happen in the case of very large,
  lost, or proprietary data sets. `TermCategoryFrequencies` is a corpus representation,that can accept this
  sort of data, along with any categorized documents that happen to be available.
  
  Let use the [Corpus of Contemporary American English](https://corpus.byu.edu/coca/) as an example.
  We'll construct a visualization
  to analyze the difference between spoken American English and English that occurs in fiction.
  
  ```python
  convention_df = (pd.read_excel('https://www.wordfrequency.info/files/genres_sample.xls')
                .dropna()
                .set_index('lemma')[['SPOKEN', 'FICTION']]
                .iloc[:1000])
  convention_df.head()
            SPOKEN    FICTION
  lemma
  the    3859682.0  4092394.0
  I      1346545.0  1382716.0
  they   609735.0   352405.0
  she    212920.0   798208.0
  would  233766.0   229865.0
  ```
  
  Transforming this into a visualization is extremely easy. Just pass a dataframe indexed on
  terms with columns indicating category-counts into the the `TermCategoryFrequencies` constructor.
  
  ```python
  term_cat_freq = st.TermCategoryFrequencies(convention_df)
  ```
  
  And call `produce_scattertext_explorer` normally:
  
  ```python
  html = st.produce_scattertext_explorer(
          term_cat_freq,
          category='SPOKEN',
          category_name='Spoken',
          not_category_name='Fiction',
  )
  ```
  
  
  [![demo_category_frequencies.html](https://jasonkessler.github.io/demo_category_frequencies.png)](https://jasonkessler.github.io/demo_category_frequencies.html)
  
  If you'd like to incorporate some documents into the visualization, you can add them into to the
  `TermCategoyFrequencies` object.
  
  First, let's extract some example Fiction and Spoken documents from the sample COCA corpus.
  
  ```python
  import requests, zipfile, io
  coca_sample_url = 'http://corpus.byu.edu/cocatext/samples/text.zip'
  zip_file = zipfile.ZipFile(io.BytesIO(requests.get(coca_sample_url).content))
  
  document_df = pd.DataFrame(
          [{'text': zip_file.open(fn).read().decode('utf-8'),
            'category': 'SPOKEN'}
           for fn in zip_file.filelist if fn.filename.startswith('w_spok')][:2]
          + [{'text': zip_file.open(fn).read().decode('utf-8'),
              'category': 'FICTION'}
             for fn in zip_file.filelist if fn.filename.startswith('w_fic')][:2])
  ```
  
  And we'll pass the `documents_df` dataframe into `TermCategoryFrequencies` via the `document_category_df`
  parameter.  Ensure the dataframe has two columns, 'text' and 'category'.  Afterward, we can
  call `produce_scattertext_explorer` (or your visualization function of choice) normally.
  
  ```python
  doc_term_cat_freq = st.TermCategoryFrequencies(convention_df, document_category_df=document_df)
  
  html = st.produce_scattertext_explorer(
          doc_term_cat_freq,
          category='SPOKEN',
          category_name='Spoken',
          not_category_name='Fiction',
  )
  ```
class_docstr_tok: ["This","class","allows","you","to","produce","scatter","plots","of","raw","term","frequency","counts",".","Occasionally",",","only","term","frequency","statistics","are","available",".","This","may","happen","in","the","case","of","very","large",",","lost",",","or","proprietary","data","sets",".","`","TermCategoryFrequencies","`","is","a","corpus","representation",",","that","can","accept","this","sort","of","data",",","along","with","any","categorized","documents","that","happen","to","be","available",".","Let","use","the","[","Corpus","of","Contemporary","American","English","]","(","https",":","\/\/corpus.byu.edu\/coca\/",")","as","an","example",".","We","'ll","construct","a","visualization","to","analyze","the","difference","between","spoken","American","English","and","English","that","occurs","in","fiction",".","``","`","python","convention_df","=","(","pd.read_excel","(","'https",":","\/\/www.wordfrequency.info\/files\/genres_sample.xls","'",")",".dropna","(",")",".set_index","(","'lemma","'",")","[","[","'SPOKEN","'",",","'FICTION","'","]","]",".iloc","[",":1000","]",")","convention_df.head","(",")","SPOKEN","FICTION","lemma","the","3859682.0","4092394.0","I","1346545.0","1382716.0","they","609735.0","352405.0","she","212920.0","798208.0","would","233766.0","229865.0","``","`","Transforming","this","into","a","visualization","is","extremely","easy",".","Just","pass","a","dataframe","indexed","on","terms","with","columns","indicating","category-counts","into","the","the","`","TermCategoryFrequencies","`","constructor",".","``","`","python","term_cat_freq","=","st.TermCategoryFrequencies","(","convention_df",")","``","`","And","call","`","produce_scattertext_explorer","`","normally",":","``","`","python","html","=","st.produce_scattertext_explorer","(","term_cat_freq",",","category='SPOKEN","'",",","category_name='Spoken","'",",","not_category_name='Fiction","'",",",")","``","`","[","!","[","demo_category_frequencies.html","]","(","https",":","\/\/jasonkessler.github.io\/demo_category_frequencies.png",")","]","(","https",":","\/\/jasonkessler.github.io\/demo_category_frequencies.html",")","If","you","'d","like","to","incorporate","some","documents","into","the","visualization",",","you","can","add","them","into","to","the","`","TermCategoyFrequencies","`","object",".","First",",","let","'s","extract","some","example","Fiction","and","Spoken","documents","from","the","sample","COCA","corpus",".","``","`","python","import","requests",",","zipfile",",","io","coca_sample_url","=","'http",":","\/\/corpus.byu.edu\/cocatext\/samples\/text.zip'","zip_file","=","zipfile.ZipFile","(","io.BytesIO","(","requests.get","(","coca_sample_url",")",".content",")",")","document_df","=","pd.DataFrame","(","[","{","'text","'",":","zip_file.open","(","fn",")",".read","(",")",".decode","(","'utf-8","'",")",",","'category","'",":","'SPOKEN","'","}","for","fn","in","zip_file.filelist","if","fn.filename.startswith","(","'w_spok","'",")","]","[",":2","]","+","[","{","'text","'",":","zip_file.open","(","fn",")",".read","(",")",".decode","(","'utf-8","'",")",",","'category","'",":","'FICTION","'","}","for","fn","in","zip_file.filelist","if","fn.filename.startswith","(","'w_fic","'",")","]","[",":2","]",")","``","`","And","we","'ll","pass","the","`","documents_df","`","dataframe","into","`","TermCategoryFrequencies","`","via","the","`","document_category_df","`","parameter",".","Ensure","the","dataframe","has","two","columns",",","'text","'","and","'category","'",".","Afterward",",","we","can","call","`","produce_scattertext_explorer","`","(","or","your","visualization","function","of","choice",")","normally",".","``","`","python","doc_term_cat_freq","=","st.TermCategoryFrequencies","(","convention_df",",","document_category_df=document_df",")","html","=","st.produce_scattertext_explorer","(","doc_term_cat_freq",",","category='SPOKEN","'",",","category_name='Spoken","'",",","not_category_name='Fiction","'",",",")","``","`"]
docstr: Parameters
  ----------
  scatterchartdata : ScatterChartData
  
  Returns
  -------
  pd.DataFrame
docstr_tok: ["Parameters","--","--","--","--","--","scatterchartdata",":","ScatterChartData","Returns","--","--","--","-","pd.DataFrame"]
code: def get_term_category_frequencies(self, scatterchartdata):
      """
      Parameters
      ----------
      scatterchartdata : ScatterChartData
  
      Returns
      -------
      pd.DataFrame
      """
  
      df = self.term_category_freq_df.rename(
          columns={
              c: str(c) + " freq" for c in self.term_category_freq_df
          }
      )
      df.index.name = "term"
      return df
  
file_path: scattertext/scattertext/TermCategoryFrequencies.py
imports: import pkgutil
  from io import StringIO
  import numpy
  import pandas
  from scattertext.Common import DEFAULT_BACKGROUND_SCALER_ALGO, DEFAULT_BACKGROUND_BETA
  from scattertext.termscoring import ScaledFScore
label_desc: Use image node_id 11 for calling the TermCategoryFrequencies obj's underlying member method code with example usage: obj.get_term_category_frequencies(scatterchartdata) and returns: df