Pandas Melt several groups of columns into multiple target columns by name
<p>I would like to melt several groups of columns of a dataframe into multiple target columns. Similar to questions <a href="https://stackoverflow.com/questions/35187963/python-pandas-melt-groups-of-initial-columns-into-multiple-target-columns">Python Pandas Melt Groups of Initial Columns Into Multiple Target Columns</a> and <a href="https://stackoverflow.com/questions/32105368/pandas-dataframe-reshaping-stacking-of-multiple-value-variables-into-seperate-co">pandas dataframe reshaping/stacking of multiple value variables into seperate columns</a>. However I need to do this explicitly by column name, rather than by index location.</p>

<pre><code>import pandas as pd
df = pd.DataFrame([('a','b','c',1,2,3,'aa','bb','cc'), ('d', 'e', 'f', 4, 5, 6, 'dd', 'ee', 'ff')],
                  columns=['a_1', 'a_2', 'a_3','b_1', 'b_2', 'b_3','c_1', 'c_2', 'c_3'])
df
</code></pre>

<p>Original Dataframe:</p>

<pre><code>    id   a_1  a_2  a_3  b_1  b_2  b_3  c_1  c_2  c_3
0   101   a    b    c    1    2    3    aa   bb   cc
1   102   d    e    f    4    5    6    dd   ee   ff
</code></pre>

<p>Target Dataframe</p>

<pre><code>     id   a   b   c
0   101   a   1   aa
1   101   b   2   bb
2   101   c   3   cc
3   102   d   4   dd
4   102   e   5   ee
5   102   f   6   ff
</code></pre>

<p>Advice is much appreciated on an approach to this.</p>