how to add a row to a Datetime Multiindex Panda Dataframe
<blockquote>
  <p>How would I go about adding a row to the top of this dataframe. This
  is downloaded data. I cannot use a specific row index in the formula
  because the first Datetime indice changes all the time. I cannot also use a 
  specific label for the inner index as it could be Datetime. Is there a
  way to generalize this?</p>
  
  <p>I tried this</p>
</blockquote>

<pre><code>df[df.index.min()[0])) - dt.timedelta(minutes=5), :] = [list to add]
</code></pre>

<blockquote>
  <p>however it only add a row at the end of the Dataframe. Sorting,</p>
</blockquote>

<pre><code>df.sort_index(inplace=True) 
</code></pre>

<blockquote>
  <p>did not help because I guess I am dealing with 2 levels of index here;
  which would explain why the row sticks to the bottom of the frame. </p>
</blockquote>

<pre><code>                        A      B      C        D     E

2006-04-28 00:00:00                                    
             A        69.62  69.62  6.518   65.09  69.62
             B
             C
2006-05-01 00:00:00  
            A         71.5   71.5  6.522   65.16   71.5
            B
            C
2006-05-02 00:00:00   
            A        72.34  72.34  6.669   66.55  72.34
            B
            C
</code></pre>

<p>The final result should look like this:
<code>X</code>'s being the elements in the list/array to be added.</p>

<pre><code>                        A      B      C        D     E
        NEWROW          X1     X2    X3       X4    X5

2006-04-28 00:00:00                                    
             A        69.62  69.62  6.518   65.09  69.62
             B
             C
2006-05-01 00:00:00  
            A         71.5   71.5  6.522   65.16   71.5
            B
            C
2006-05-02 00:00:00   
            A        72.34  72.34  6.669   66.55  72.34
            B
            C
</code></pre>

<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow"><code>sort_index</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sortlevel.html" rel="nofollow"><code>sortlevel</code></a> for me does <strong>not</strong> work with <code>Multiindex</code>:</p>

<p>So you can use little <code>hack</code> - first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a> with second level <code>Stats</code>, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow"><code>sort_index</code></a> and last <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> back with parameter <code>append=True</code>:</p>

<pre><code>df1 = df1.sort_index()

df1.loc[((df1.index.min()[0]) -  dt.timedelta(minutes=5), 'SUM'),:] = 
df1.loc[(slice(None), slice('price')),:].sum()

df1 = df1.reset_index('Stats')
df1 = df1.sort_index(axis=0).set_index('Stats', append=True)
print (df1)
                                 A       B       C       D       E
Date                Stats                                         
2006-04-27 23:55:00 SUM     213.46  213.46  19.709  196.80  213.46
2006-04-28 00:00:00 price    69.62   69.62   6.518   65.09   69.62
                    std        NaN     NaN     NaN     NaN     NaN
                    weight     NaN     NaN     NaN     NaN     NaN
2006-05-01 00:00:00 price    71.50   71.50   6.522   65.16   71.50
                    std        NaN     NaN     NaN     NaN     NaN
                    weight     NaN     NaN     NaN     NaN     NaN
2006-05-02 00:00:00 price    72.34   72.34   6.669   66.55   72.34
                    std        NaN     NaN     NaN     NaN     NaN
                    weight     NaN     NaN     NaN     NaN     NaN
</code></pre>

python pandas dataframe append multi-index