title: Using Pandas Melt() to pivot on two sets of data
body: <p>I have cell phone usage and bill data arranged in the <code>Pandas</code> <code>dataframe</code> that has stats for two months of data. I'd like to pivot the data so that columns for each month become rows.</p>
  
  <p>Starting point:</p>
  
  <pre><code>       Name  Jan Minutes Used  Feb Minutes Used Jan Bill Paid Feb Bill Paid
  0  Person A                10                11           Yes            No
  1  Person B                12                13            No           Yes
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>       Name Month  Minutes Used Bill Paid
  0  Person A   Jan           10        Yes
  1  Person A   Feb           11         No
  2  Person B   Jan           12         No
  3  Person B   Feb           13        Yes
  </code></pre>
  
  <p>I am trying to use <code>.melt()</code> to transpose the data, but Bill Paid and Minutes Used data are getting put in the same column where they should be broken out into two columns.</p>
  
  <p>My code:</p>
  
  <pre><code>import pandas as pd
  df = pd.DataFrame(data=[['Person A', 10, 11, 'Yes', 'No'], ['Person B', 12, 13, 'No', 'Yes']], columns=['Name', 'Jan Minutes Used', 'Feb Minutes Used', 'Jan Bill Paid', 'Feb Bill Paid'])
  
  melted_df = pd.melt(df.reset_index(),
                   id_vars=['Name'],
                   value_vars=['Jan Bill Paid','Feb Bill Paid', 'Jan Minutes Used', 'Feb Minutes Used'])
  
  melted_df['variable'] = melted_df['variable'].str.replace(' Minutes Used', '').str.replace(' Bill Paid', '')
  melted_df.columns = ['Name', 'Month', 'Bill Paid']
  
  print melted_df
  </code></pre>
  
  <p>My code's output:</p>
  
  <pre><code>       Name Month Bill Paid
  0  Person A   Jan       Yes
  1  Person B   Jan        No
  2  Person A   Feb        No
  3  Person B   Feb       Yes
  4  Person A   Jan        10
  5  Person B   Jan        12
  6  Person A   Feb        11
  7  Person B   Feb        13
  </code></pre>