title: convert dataframe to nested json
body: <p>I am using </p>
  
  <pre><code>pd.read_sql_query() 
  </code></pre>
  
  <p>to get data from database and then use </p>
  
  <pre><code>to_json(orient='records') 
  </code></pre>
  
  <p>this is the dataframe:</p>
  
  <pre><code>(1)
    price_formula_id  premium  product_id  exchange  product_name  product_code   weight  
  0            30064      0.0        c001       CME          2018            CL      0.3
  1            30064      0.0        c002       CME          2018            CL      0.7
  
  (2)
  price_formula_id  premium  product_id  exchange  product_name  product_code   weight  
  0            30064      NONE        c001       CME          2018            CL      0.3
  1            30064      NONE        c002       CME          2018            CL      0.7
  </code></pre>
  
  <p>to convert to this formation.</p>
  
  <pre><code>[{
      "price_formula_id": "30064",
      "premium": "0.0",
      "product_id": "c001",
      "exchange": "CME",
      "product_name": "2018",
      "product_code": "CL",
      "weight": "0.3"
  },
  {
      "price_formula_id": "30064",
      "premium": "0.0",
      "product_id": "c002",
      "exchange": "CME",
      "product_name": "2018",
      "product_code": "CL",
      "weight": "0.7"
  }]
  </code></pre>
  
  <p>but what I really want should be like this :</p>
  
  <pre><code> { 
     "price_formula_id": "30064",
     "premium": "0.0",
     "basket": 
      [
       {"product_id": "c001",
        "exchange": "CME",
        "product_name": "2018",
        "product_code": "CL",
        "weight": "0.3"
       },
       {
        "product_id": "c002",
        "exchange": "CME",
        "product_name": "2018",
        "product_code": "CL",
        "weight": "0.7"
       }
      ]
   }
  </code></pre>
  
  <p>I need to group the same info and set a new index 'basket' for the rest.
  how could I make it?
  Thanks very much.</p>