Flatten pandas pivot table
<p>This is a follow up of my <a href="http://stackoverflow.com/questions/39229005/pivot-table-no-numeric-types-to-aggregate/39229396#39229396">question</a>. Rather than a pivot table, is it possible to flatten table to look like the following:</p>

<pre><code>data = {'year': ['2016', '2016', '2015', '2014', '2013'],
    'country':['uk', 'usa', 'fr','fr','uk'],
    'sales': [10, 21, 20, 10,12],
    'rep': ['john', 'john', 'claire', 'kyle','kyle']
    }

pd.DataFrame(data).pivot_table(index='country', columns='year', values=['rep','sales'])

          rep                       sales                  
year     2013  2014    2015  2016   2013  2014  2015  2016
country                                                  
fr       None  kyle  claire  None   None    10    20  None
uk       kyle  None    None  john    12  None  None    10
usa      None  None    None  john   None  None  None    21
</code></pre>

<p>Flattened table:</p>

<pre><code>        rep_2013 rep_2014 rep_2015 rep_2016  sales_2013  sales_2014  sales_2015  sales_2016
country                                                  
fr       None    kyle     claire    None      None        10            20          None
uk       kyle    None     None      john      12          None          None         10
usa      None    None     None      john      None        None          None         21
</code></pre>

<p>Try this:</p>

<pre><code>df.columns = df.columns.get_level_values(0)
</code></pre>

<p>followed by: </p>

<pre><code>df.columns = [' '.join(col).strip() for col in df.columns.values]
</code></pre>

<p>This should flatten your multi-index </p>

python pandas