title: Flattening pandas DataFrame
body: <p>I have a dataframe that looks similar to the following</p>
  
  <pre><code>import pandas as pd
  df = pd.DataFrame(data={"CommonIdentifier":[1234,1235,1236,1237],
                          "CommonValue":["type1","type2","type1","type1"],
                          "Identifier1":["a","a","b","b"],
                          "Value1":[1,1.5,2,1.3],
                          "Identifier2":["b","b","c","a"],
                           "Value2":[4,2,3.2,1]})
  df
  
   CommonIdentifier CommonValue Identifier1 Identifier2 Value1 Value2
  0            1234       type1           a           b    1.0    4.0
  1            1235       type2           a           b    1.5    2.0
  2            1236       type1           b           c    2.0    3.2
  3            1237       type1           b           a    1.3    1.0
  </code></pre>
  
  <p>and I would like to manipulate it so it is of the form</p>
  
  <pre><code>pd.DataFrame(data={"CommonIdentifier":[1234,1235,1236,1237,1234,1235,1236,1237],
                     "CommonValue":["type1","type2","type1","type1","type1","type2","type1","type1"],
                     "IdentifierJoined":["a","a","b","b","b","b","c","a"],
                     "ValueJoined":[1,1.5,2,1.3,4,2,3.2,1]})
  
      CommonIdentifier    CommonValue IdentifierJoined    ValueJoined
  0               1234          type1                a            1.0
  1               1235          type2                a            1.5
  2               1236          type1                b            2.0
  3               1237          type1                b            1.3
  4               1234          type1                b            4.0
  5               1235          type2                b            2.0
  6               1236          type1                c            3.2
  7               1237          type1                a            1.0
  </code></pre>
  
  <p>The above is just representative, in actuality I have 9 Identifiers/Value pairs. I was wondering how I could go about accomplishing this in a succinct way. I have come up with the following</p>
  
  <pre><code>num_identifiers = 2
  m1 = pd.melt(df,id_vars=['CommonIdentifier'],
               value_vars=['Value1','Value2'])
  m2 = pd.melt(df,id_vars=['CommonIdentifier'],
               value_vars=['Identifier1','Identifier2'])
  m3 = pd.concat([df[["CommonIdentifier","CommonValue"]]] * num_identifiers)
  m3.index = range(len(m3))
  
  pd.concat([m3[["CommonIdentifier","CommonValue"]],
             m2[["value"]].rename(columns={"value":"IdentifierJoined"}),
             m1[["value"]].rename(columns={"value":"ValueJoined"})], axis=1)
  </code></pre>
  
  <p>which accomplishes this transformation however it feels fairly sloppy/longwinded</p>