title: How to insert a mini identity matrix (row and column) to the start of Panda dataframe
body: <p>Given a data frame as such:</p>
  
  <pre><code>+-----+-----+-----+------+
  |  X1 | xyz | opq |  jkl |
  +-----+-----+-----+------+
  | abc | 0.9 | 0.0 |  0.5 |
  +-----+-----+-----+------+
  | efg | 0.3 | 0.0 |  0.0 |
  +-----+-----+-----+------+
  | lmn | 0.0 | 0.23|  0.0 |
  +-----+-----+-----+------+
  </code></pre>
  
  <p><strong>How do I add an identity matrix to the start of the dataframe to get this?</strong>:</p>
  
  <pre><code>+-----+-----+-----+------+------+
  |  X1 | &lt;s&gt; | opq |  jkl |  jkl |
  +-----+-----+-----+------+------+
  | &lt;s&gt; | 1.0 | 0.0 | 0.0  |  0.0 |
  +-----+-----+-----+------+------+
  | abc | 0.0 | 0.9 | 0.0  |  0.5 |
  +-----+-----+-----+------+------+
  | efg | 0.0 | 0.3 | 0.0  |  0.0 |
  +-----+-----+-----+------+------+
  | lmn | 0.0 | 0.0 | 0.23 |  0.0 |
  +-----+-----+-----+------+------+
  </code></pre>
  
  <p>That's adding a 1x1 matrix but is there a way to add a nxn matrix, e.g.:</p>
  
  <pre><code>+-----+-----+-----+------+------+------+
  |  X1 | &lt;s&gt; | &lt;e&gt; | opq  |  jkl |  jkl |
  +-----+-----+-----+------+------+------+
  | &lt;s&gt; | 1.0 | 0.0 | 0.0  |  0.0 |  0.0 |
  +-----+-----+-----+------+------+------+
  | &lt;e&gt; | 0.0 | 1.0 | 0.0  |  0.0 |  0.0 |
  +-----+-----+-----+------+------+------+
  | abc | 0.0 | 0.0 | 0.9  | 0.0  |  0.5 |
  +-----+-----+-----+------+------+------+
  | efg | 0.0 | 0.0 | 0.3  | 0.0  |  0.0 |
  +-----+-----+-----+------+------+------+
  | lmn | 0.0 | 0.0 | 0.0  | 0.23 |  0.0 |
  +-----+-----+-----+------+------+------+
  </code></pre>
  
  <p>I've tried this:</p>
  
  <pre><code>$ echo -e 'abc\txyz\t0.9\nefg\txyz\t0.3\nlmn\topq\t0.23\nabc\tjkl\t0.5\n' &gt; test.txt
  $ cat test.txt
  abc xyz 0.9
  efg xyz 0.3
  lmn opq 0.23
  abc jkl 0.5
  
  $ python
  &gt;&gt;&gt; from sframe import SFrame
  &gt;&gt;&gt; sf = SFrame.read_csv('test.txt', header=False, delimiter='\t', column_type_hints=[unicode, unicode, float])
  [INFO] sframe.cython.cy_server: SFrame v2.1 started. Logging /tmp/sframe_server_1479779504.log
  &gt;&gt;&gt; df = sf.to_dataframe()
  &gt;&gt;&gt; df
      X1   X2    X3
  0  abc  xyz  0.90
  1  efg  xyz  0.30
  2  lmn  opq  0.23
  3  abc  jkl  0.50
  &gt;&gt;&gt; df = df.pivot(index='X1', columns='X2', values='X3') 
  &gt;&gt;&gt; df
  X2   jkl   opq  xyz
  X1                 
  abc  0.5   NaN  0.9
  efg  NaN   NaN  0.3
  lmn  NaN  0.23  NaN
  &gt;&gt;&gt; df.fillna(0) 
  X2   jkl   opq  xyz
  X1                 
  abc  0.5  0.00  0.9
  efg  0.0  0.00  0.3
  lmn  0.0  0.23  0.0
  </code></pre>
  
  <p>First I added a column:</p>
  
  <pre><code>&gt;&gt;&gt; numrow, numcol = df.shape
  &gt;&gt;&gt; df.insert(0, '&lt;s&gt;', [0.0] * numrow)
  &gt;&gt;&gt; df
  X2   &lt;s&gt;  jkl   opq  xyz
  X1                      
  abc  0.0  0.5  0.00  0.9
  efg  0.0  0.0  0.00  0.3
  lmn  0.0  0.0  0.23  0.0
  </code></pre>
  
  <p>Then add the row and change the value of <code>df['&lt;s&gt;']['&lt;s&gt;']</code>:</p>
  
  <pre><code>&gt;&gt;&gt; numrow, numcol = df.shape
  &gt;&gt;&gt; df.loc['&lt;s&gt;'] = [0.0]*numcol
  &gt;&gt;&gt; df
  X2   &lt;s&gt;  jkl   opq  xyz
  X1                      
  abc  0.0  0.5  0.00  0.9
  efg  0.0  0.0  0.00  0.3
  lmn  0.0  0.0  0.23  0.0
  &lt;s&gt;  0.0  0.0  0.00  0.0
  &gt;&gt;&gt; df['&lt;s&gt;']['&lt;s&gt;'] = 1.0
  &gt;&gt;&gt; df
  X2   &lt;s&gt;  jkl   opq  xyz
  X1                      
  abc  0.0  0.5  0.00  0.9
  efg  0.0  0.0  0.00  0.3
  lmn  0.0  0.0  0.23  0.0
  &lt;s&gt;  1.0  0.0  0.00  0.0
  </code></pre>
  
  <p>But still I need to swap the last row and put it to the first and push down all other rows in the table. <strong>How do I do that?</strong></p>
  
  <p>And there must be a better / easier way to do this.</p>