title: Python Pandas: how to turn a DataFrame with "factors" into a design matrix for linear regression?
body: <p>If memory servies me, in R there is a data type called factor which when used within a DataFrame can be automatically unpacked into the necessary columns of a regression design matrix.  For example, a factor containing True/False/Maybe values would be transformed into:</p>
  
  <pre><code>1 0 0
  0 1 0
  or
  0 0 1
  </code></pre>
  
  <p>for the purpose of using lower level regression code.  Is there a way to achieve something similar using the pandas library?  I see that there is some regression support within Pandas, but since I have my own customised regression routines I am really interested in the construction of the design matrix (a 2d numpy array or matrix) from heterogeneous data with support for mapping back and fort between columns of the numpy object and the Pandas DataFrame from which it is derived.</p>
  
  <p>Update: Here is an example of a data matrix with heterogeneous data of the sort I am thinking of (the example comes from the Pandas manual):</p>
  
  <pre><code>&gt;&gt;&gt; df2 = DataFrame({'a' : ['one', 'one', 'two', 'three', 'two', 'one', 'six'],'b' : ['x', 'y', 'y', 'x', 'y', 'x', 'x'],'c' : np.random.randn(7)})
  &gt;&gt;&gt; df2
         a  b         c
  0    one  x  0.000343
  1    one  y -0.055651
  2    two  y  0.249194
  3  three  x -1.486462
  4    two  y -0.406930
  5    one  x -0.223973
  6    six  x -0.189001
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>The 'a' column should be converted into 4 floating point columns (in spite of the meaning, there are only four unique atoms), the 'b' column can be converted to a single floating point column, and the 'c' column should be an unmodified final column in the design matrix. </p>
  
  <p>Thanks,</p>
  
  <p>SetJmp</p>