Pandas: Is there a way to use something like 'droplevel' and in process, rename the the other level using the dropped level labels as prefix/suffix?
<p>Screenshot of the query below:</p>

<p><a href="http://i.stack.imgur.com/dGNAV.png" rel="nofollow"><img src="http://i.stack.imgur.com/dGNAV.png" alt="Groupby Query"></a></p>

<p>Is there a way to easily drop the upper level column index and a have a single level with labels such as <code>points_prev_amax</code>, <code>points_prev_amin</code>, <code>gf_prev_amax</code>, <code>gf_prev_amin</code> and so on?  </p>

<p>Using @jezrael's setup</p>

<pre><code>df = pd.DataFrame({'A':[1,2,2,1],
                   'B':[4,5,6,4],
                   'C':[7,8,9,1],
                   'D':[1,3,5,9]})

df = df.groupby('A').agg([max, min])
</code></pre>

<hr>

<p>Assign new columns with</p>

<pre><code>from itertools import starmap

def flat(midx, sep=''):
    fstr = sep.join(['{}'] * midx.nlevels)
    return pd.Index(starmap(fstr.format, midx))

df.columns = flat(df.columns, '_')

df
</code></pre>

<p><a href="http://i.stack.imgur.com/xHakS.png" rel="nofollow"><img src="http://i.stack.imgur.com/xHakS.png" alt="enter image description here"></a></p>

python pandas rename multiple-columns multi-index