title: pivoting pandas dataframe into prefixed cols, not a MultiIndex
body: <p>I have a timeseries dataframe that is similar to:</p>
  
  <pre><code>ts = pd.DataFrame([['Jan 2000','WidgetCo',0.5, 2], ['Jan 2000','GadgetCo',0.3, 3], ['Jan 2000','SnazzyCo',0.2, 4],
            ['Feb 2000','WidgetCo',0.4, 2], ['Feb 2000','GadgetCo',0.5, 2.5], ['Feb 2000','SnazzyCo',0.1, 4],
            ], columns=['month','company','share','price'])
  </code></pre>
  
  <p>Which looks like:</p>
  
  <pre><code>  month   company  share  price
  0  Jan 2000  WidgetCo    0.5    2.0
  1  Jan 2000  GadgetCo    0.3    3.0
  2  Jan 2000  SnazzyCo    0.2    4.0
  3  Feb 2000  WidgetCo    0.4    2.0
  4  Feb 2000  GadgetCo    0.5    2.5
  5  Feb 2000  SnazzyCo    0.1    4.0
  </code></pre>
  
  <p>I can pivot this table like so:</p>
  
  <pre><code>pd.pivot_table(ts,index='month', columns='company')
  </code></pre>
  
  <p>Which gets me:</p>
  
  <pre><code>            share                      price                  
  company  GadgetCo SnazzyCo WidgetCo GadgetCo SnazzyCo WidgetCo
  month                                                         
  Feb 2000      0.5      0.1      0.4      2.5        4        2
  Jan 2000      0.3      0.2      0.5      3.0        4        2
  </code></pre>
  
  <p>This is what I want except that I need to collapse the <code>MultiIndex</code> so that the <code>company</code> is used as a prefix for <code>share</code> and <code>price</code> like so:</p>
  
  <pre><code>          WidgetCo_share  WidgetCo_price  GadgetCo_share  GadgetCo_price   ...
  month                                                                      
  Jan 2000             0.5               2             0.3             3.0   
  Feb 2000             0.4               2             0.5             2.5   
  </code></pre>
  
  <p>I came up with this function to do just that but it seems like a poor solution:</p>
  
  <pre><code>def pivot_table_to_flat(df, column, index):
      res = df.set_index(index)
      cols = res.drop(column, axis=1).columns.values
      resulting_cols = []
      for prefix in res[column].unique():
          for col in cols:
              new_col_name = prefix + '_' + col
              res[new_col_name] = res[res[column] == prefix][col]
              resulting_cols.append(new_col_name)
  
      return res[resulting_cols]
  
  pivot_table_to_flat(ts, index='month', column='company')
  </code></pre>
  
  <p>What is a better way of accomplishing a pivot resulting in a columns with prefixes as opposed to a <code>MultiIndex</code>?</p>