title: How to create corpus from pandas data frame to operate with NLTK
body: <p>Here is my problem:</p>
  
  <ol>
  <li><p>I have a csv file containing articles data set with columns: ID, CATEGORY, TITLE, BODY.</p></li>
  <li><p>In python, I read the file to a pandas data frame like this:</p>
  
  <pre><code>import pandas as pd
  df = pd.read_csv('my_file.csv')
  </code></pre></li>
  <li><p>Now I need to transform somehow this <code>df</code> to get a corpus object, let's call it <code>my_corpus</code>. But how exactly I can do it? I assume I need to use:</p>
  
  <pre><code>from nltk.corpus.reader import CategorizedCorpusReader
  my_corpus = some_nltk_function(df) # &lt;- what is the function?
  </code></pre></li>
  <li><p>At the end I can use NLTK methods to analyze the corpus. For example:</p>
  
  <pre><code>import nltk
  my_corpus.fileids() # &lt;- I expect values from column ID
  my_corpus.categories() # &lt;- I expect values from column CATEGORY
  my_corpus.words(categories='cat_A') # &lt;- I expect values from column TITLE and BODY
  my_corpus.sents(categories=['cat_A', 'cat_B', 'cat_C']) # &lt;- I expect values from column TITLE and BODY
  </code></pre></li>
  </ol>
  
  <p>Please, advise.</p>