turn a pivot table from pandas into a flat tabular format with a single header row
<p>What's the easiest way to turn my pandas dataframe into a dataframe which has one header row and the two columns</p>

<p>from this:</p>

<pre><code>          date  today
index       
1   2016-07-01  2016-09-08
2   2016-07-01  2016-09-08
3   2016-07-01  2016-09-08
4   2016-07-01  2016-09-08
</code></pre>

<p>into this:</p>

<pre><code>index      date     today   
1   2016-07-01  2016-09-08
2   2016-07-01  2016-09-08
3   2016-07-01  2016-09-08
4   2016-07-01  2016-09-08
</code></pre>

<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a>:</p>

<pre><code>print (df.columns)
Index(['date', 'today'], dtype='object')

print (df.index)
Int64Index([1, 2, 3, 4], dtype='int64', name='index')

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

<p>Or:</p>

<pre><code>df = df.reset_index()

print (df)
   index        date       today
0      1  2016-07-01  2016-09-08
1      2  2016-07-01  2016-09-08
2      3  2016-07-01  2016-09-08
3      4  2016-07-01  2016-09-08

print (df.index)
RangeIndex(start=0, stop=4, step=1)
</code></pre>

<hr>

<p>If need remove column <code>index</code>, add parameter <code>drop=True</code>:</p>

<pre><code>df.reset_index(inplace=True, drop=True)
print (df)
         date       today
0  2016-07-01  2016-09-08
1  2016-07-01  2016-09-08
2  2016-07-01  2016-09-08
3  2016-07-01  2016-09-08
</code></pre>

<p>But if need only remove text <code>index</code> use <a href="http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#changes-to-rename" rel="nofollow"><code>rename_axis</code></a> (new in <code>pandas</code> <code>0.18.0</code>):</p>

<pre><code>df = df.rename_axis(None)
</code></pre>

<p>Or:</p>

<pre><code>#all versions
df.index.name = None

print (df)
         date       today
1  2016-07-01  2016-09-08
2  2016-07-01  2016-09-08
3  2016-07-01  2016-09-08
4  2016-07-01  2016-09-08

print (df.index)
Int64Index([1, 2, 3, 4], dtype='int64')
</code></pre>

python pandas dataframe