title: scipy dendrogram to json for d3.js tree visualisation
body: <p>I am trying to convert results of scipy hierarchical clustering  into json for display in d3.js here <a href="http://bl.ocks.org/mbostock/4063550" rel="noreferrer">an example</a></p>
  <p>The following codes produces a dendrogram with 6 branches.</p>
  <pre><code>import pandas as pd 
  import scipy.spatial
  import scipy.cluster
  
  d = {'employee' : ['A', 'B', 'C', 'D', 'E', 'F'],
   'skillX': [2,8,3,6,8,10],
   'skillY': [8,15,6,9,7,10]}
  
  d1 = pd.DataFrame(d)
  
  distMat = xPairWiseDist = scipy.spatial.distance.pdist(np.array(d1[['skillX', 'skillY']]), 'euclidean')
  clusters = scipy.cluster.hierarchy.linkage(distMat, method='single')
  dendo  = scipy.cluster.hierarchy.dendrogram(clusters, labels = list(d1.employee), orientation = 'right')
  
  dendo
  </code></pre>
  <p><strong>my question</strong>
  How can I represent the data in a json file in a format that d3.js understand</p>
  <pre><code>{'name': 'Root1’, 
        'children':[{'name' : 'B'},
                    {'name': 'E-D-F-C-A',
                             'children' : [{'name': 'C-A',
                                           'children' : {'name': 'A'}, 
                                                        {'name' : 'C'}]
                                                   }
                     }
                     ]
  }
  </code></pre>
  <p>The embarassing truth is that I do not know if I can extract this information from the <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.dendrogram.html" rel="noreferrer">dendogram</a> or from the <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage" rel="noreferrer">linkage matrix </a> and <strong>how</strong></p>
  <p>I am thankful for any help I can get.</p>
  <p><strong>EDIT TO CLARIFY</strong></p>
  <p>So far, I have tried to use the <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.to_tree.html#scipy.cluster.hierarchy.to_tree" rel="noreferrer">totree</a> method but have difficulties understanding its structure (yes, I read the documentation).</p>
  <pre><code>a = scipy.cluster.hierarchy.to_tree(clusters , rd=True)
  
  for x in a[1]:
   #print x.get_id()
   if x.is_leaf() != True :
       print  x.get_left().get_id(), x.get_right().get_id(), x.get_count()
  </code></pre>