title: Converting CSV to Hierarchical JSON output
body: <p>I am trying to convert the CSV file into a Hierarchical JSON file.CSV file input as follows, It contains two columns Gene and Disease.</p>
  <pre><code>gene,disease
  A1BG,Adenocarcinoma
  A1BG,apnea
  A1BG,Athritis
  A2M,Asthma
  A2M,Astrocytoma
  A2M,Diabetes
  NAT1,polyps
  NAT1,lymphoma
  NAT1,neoplasms
  </code></pre>
  <p>The expected Output format should be in the following format</p>
  <pre><code>{
       &quot;name&quot;: &quot;A1BG&quot;,
       &quot;children&quot;: [
        {&quot;name&quot;: &quot;Adenocarcinoma&quot;},
        {&quot;name&quot;: &quot;apnea&quot;},
        {&quot;name&quot;: &quot;Athritis&quot;}
        ]
      },
  
  {
       &quot;name&quot;: &quot;A2M&quot;,
       &quot;children&quot;: [
        {&quot;name&quot;: &quot;Asthma&quot;},
        {&quot;name&quot;: &quot;Astrocytoma&quot;},
        {&quot;name&quot;: &quot;Diabetes&quot;}
        ]
      },
  
  
  {
       &quot;name&quot;: &quot;NAT1&quot;,
       &quot;children&quot;: [
        {&quot;name&quot;: &quot;polyps&quot;},
        {&quot;name&quot;: &quot;lymphoma&quot;},
        {&quot;name&quot;: &quot;neoplasms&quot;}
        ]
      }
     
  </code></pre>
  <p>The python code I have written is below. let me know where I need to change to get the desired output.</p>
  <pre><code>import json
  finalList = []
  finalDict = {}
  grouped = df.groupby(['gene'])
  
  for key, value in grouped:
  
      dictionary = {}
      dictList = []
      anotherDict = {}
  
      j = grouped.get_group(key).reset_index(drop=True)
      dictionary['name'] = j.at[0, 'gene']
  
      for i in j.index:    
          anotherDict['disease'] = j.at[i, 'disease']
          dictList.append(anotherDict)
  
      dictionary['children'] = dictList
      finalList.append(dictionary)
  
  with open('outputresult3.json', &quot;w&quot;) as out:
      json.dump(finalList,out)
  </code></pre>