我有一个像这样的定向径向树:
G.edges(data=True)
`[('data scientist', 'senior consultant', {'frequency': 4}),
('data scientist', 'consultant', {'frequency': 11}),
('data scientist', 'postdoctoral fellow', {'frequency': 4}),
('data scientist', 'senior software developer', {'frequency': 6}),
('data scientist', 'project manager', {'frequency': 6}),
('data scientist', 'data analyst', {'frequency': 6}),
('data scientist', 'developer', {'frequency': 8}),
('data scientist', 'rd engineer', {'frequency': 4}),
('data scientist', 'research scientist', {'frequency': 4}),
('data scientist', 'director of engineering', {'frequency': 4}),
('data scientist', 'chief information officer', {'frequency': 4}),
('data scientist', 'research assistant', {'frequency': 18}),
('data scientist', 'data architect', {'frequency': 10}),
('data scientist', 'teaching assistant', {'frequency': 4}),
('data scientist', 'software engineer', {'frequency': 6})]`
我使用此function导出了它:
data = json_graph.tree_data(G, root='data scientist')
然而,这仅包括父母,子女关系,并且不保留额外的属性“频率”。我希望每个节点都有。这就是我想要的数据:
`{'children': [
{'id': 'senior consultant', 'frequency': 4},
{'id': 'consultant', 'frequency': 11},
...
{'id': 'software engineer', 'frequency': 6}],
'id': 'data scientist'}`
注意:这只是一个包含更多级别子级的更大数据集的示例。我目前正在使用源代码here,但如果有人有更好的解决方案我会全力以赴!