Created
June 25, 2015 11:04
converting scipy hieraraichal clusters to d3js json format for sunburst visualization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tod3json(node, copy_json, child_Array): | |
if(node.left or node.right): | |
copy_json = {"name" : node.id} | |
copy_json["children"] = [] | |
if(node.left): | |
child_Array = tod3json(node.left, copy_json, child_Array) | |
# print child_Array | |
copy_json["children"].append(child_Array) | |
if(node.right): | |
child_Array = tod3json(node.right, copy_json, child_Array) | |
# print child_Array | |
copy_json["children"].append(child_Array) | |
return copy_json | |
else: | |
copy_json = {"name":node.id,"hotel_id":a[node.id,0],"hotel_amenities":a[node.id,1:].tolist()} | |
return copy_json | |
copy_json = {} | |
final_json = tod3json(tree, copy_json, child_Array = []) | |
final_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment