I'm trying to create a nested JSON object from a hierarchical DataFrame (python 3.5) to feed into JavaScript to render an Org Chart. I'm essentially trying to create the structure found in the answer of this question: Organization chart - tree, online, dynamic, collapsible, pictures - in D3
An example dataframe:
df = pd.DataFrame({\
'Manager_Name':['Mike' ,'Jon', 'Susan' ,'Susan' ,'Joe'],\
'Manager_Title':['Level1' ,'Level2' ,'Level3' ,"Level3", 'Level4'],\
'Employee_Name':['Jon' ,'Susan' ,'Josh' ,'Joe' ,'Jimmy'],\
'Employee_Title':["Level2" ,"Level3" ,"Level4" ,"Level4" ,"Level5"]})
The desired output would be:
"Name": "Mike"
"Title": "Level1"
"Employees": [{
"Name": "Jon"
"Title": "Level2"
"Employees": [{
"Name": "Susan"
"Title": "Level3"
"Employees": [{
...
...
...
}]
}]
}]
I know this isn't a code generating service but I've tried applying other similarly related answers and can't seem to apply those answers here. I also haven't worked with dictionaries that much (I'm more of an R person) so there's probably some noobishness to this question. I've more time than I should on this yet I'm sure someone here can do this in a few minutes.
Other questions:
- pandas groupby to nested json
- Creating nested Json structure with multiple key values in Python from Json
- How to build a JSON file with nested records from a flat data table?
Thanks in advance!