How to use pd.melt for two rows as headers
<p>I have a dataframe that looks like this:</p>

<pre><code>   DATETIME              |  TAGNAME1          |  TAGNAME2

0  DESCRIPTION           |  TAG_DESCRIPTION   | TAG2_DESCRIPTION

1  01/01/2015 00:00:00   |  100               | 200
</code></pre>

<p>I need to have following result</p>

<pre><code>   DATETIME             | TAGNAME   |  DESCRIPTION       | VALUE

0  01/01/2015 00:00:00  | TAGNAME1  | TAG1_DESCRIPTION   | 100

1  01/01/2015 00:00:00  | TAGNAME2  | TAG2_DESCRIPTION   | 200
</code></pre>

<p>I saw some examples using pd.melt so I ran following command</p>

<pre><code>pd.melt(df, id_vars=['DATETIME'], var_name=['TagName'], value_name='Value')
</code></pre>

<p>But I am missing the DESCRIPTION as a new column</p>

<p>is there any way to achieve what i need?</p>

<p>Thanks in advance</p>

<p>Consider slicing dataframe by rows and running two melts with final merge:</p>

<pre><code>from io import StringIO
import pandas as pd

data = '''DATETIME|TAGNAME1|TAGNAME2
DESCRIPTION|TAG_DESCRIPTION|TAG2_DESCRIPTION
1/01/2015 00:00:00|100|200'''

df = pd.read_table(StringIO(data), sep="|")
#              DATETIME         TAGNAME1          TAGNAME2
# 0         DESCRIPTION  TAG_DESCRIPTION  TAG2_DESCRIPTION
# 1  1/01/2015 00:00:00              100               200

df1 = df[0:1]        # FIRST ROW
df2 = df[1:len(df)]  # SECOND TO LAST ROW

mdf = pd.merge(pd.melt(df1, id_vars=['DATETIME'], var_name='TAGNAME',
                       value_name='DESCRIPTION')[['TAGNAME', 'DESCRIPTION']],
               pd.melt(df2, id_vars=['DATETIME'], var_name='TAGNAME',
                       value_name='VALUE'),
               on=['TAGNAME'])

mdf = mdf[['DATETIME', 'TAGNAME', 'DESCRIPTION', 'VALUE']]
#              DATETIME   TAGNAME       DESCRIPTION VALUE
# 0  1/01/2015 00:00:00  TAGNAME1   TAG_DESCRIPTION   100
# 1  1/01/2015 00:00:00  TAGNAME2  TAG2_DESCRIPTION   200
</code></pre>

python pandas