title: Conceptual - How to build a 2D word-frequency matrix in Python?
body: <p>I'm trying to practice a logistic regression technique for categorizing text, and I want to build a dataset in the form of a p x n matrix, p rows for plays and n columns for unique words. I already have a text to work from, I just need to count the words in it.</p>
  
  <p>It's important to keep track of which word occurs in which play, so for a given play I've been able to create a Python dictionary that tallies unique words. What I DON'T know how to do is to combine these dicts, so that, e.g.</p>
  
  <pre><code>romeo = {[alas,2],[julliet,35]}
  caesar = {[et,1],[tu,3],[cassius,12]}
  </code></pre>
  
  <p>can be merged to produce a matrix</p>
  
  <pre><code>      alas  julliet  et  tu cassius
  romeo  2        35    0   0  0 
  caesar 0        0     1   3  12
  </code></pre>
  
  <p>For clarity I created an example where each play is composed only of unique words - naturally in reality this is not at all true.</p>
  
  <p>How might someone go about building this matrix from these dictionaries? Would it be easier to start from somewhere else?</p>