title: How to indicate the multi index columns using read_sql_query (pandas dataframes)
body: <p>I have a table with the following columns:</p>
  
  <pre><code>| Date | ProductId | SubProductId | Value |
  </code></pre>
  
  <p>I am trying to retrieve the data from that table and to put it in a pandas DataFrame.</p>
  
  <p>I want the DataFrame to have the following structure:</p>
  
  <ul>
  <li>index: dates</li>
  <li>columns: products </li>
  <li>sub-columns: sub-products</li>
  </ul>
  
  <blockquote>
  <pre><code>(products)    1              2               ...          
  (subproducts) 1    2    3    1    2    3     ...     
  date
  2015-01-02   val val val   ...
  2015-01-03   val val val   ...
  2015-01-04   ...  
  2015-01-05     
  ... 
  </code></pre>
  </blockquote>
  
  <p>I already have dataframes with the products and the subproducts and the dates.</p>
  
  <p>I understand that I need to use the <strong>MultiIndex</strong>, here is what I tried:</p>
  
  <pre><code>query ="SELECT Date, ProductId, SubProductId, Value " \
      " FROM table "\
      " WHERE SubProductId in (1,2,3)"\
      " AND ProductId in (1,2,3)"\
      " AND Date BETWEEN '2015-01-02' AND '2015-01-08' "\
      " GROUP BY Date, ProductId, SubProductId, Value "\
      " ORDER BY Date, ProductId, SubProductId "  
  
  
  
  df = pd.read_sql_query(query, conn, index_col=pd.MultiIndex.from_product([df_products['products'].tolist(), df_subproducts['subproducts'].tolist()])
  </code></pre>
  
  <p>But it does not work because the query returns a vector of "value" (shape is nb of value x 1), while I need to have a matrix (shape: nb of distinct dates x (nb of subproducts*nb of prodcuts)) in the dataframe.</p>
  
  <p>How can it be achieved:</p>
  
  <ul>
  <li>directly via the read sql query ?</li>
  <li>or  by "trandofrming" the dataframe once the database values inserted in ?</li>
  </ul>
  
  <p>NB: I am using Microsoft SQL Server.</p>