我在尝试从数据框的列中添加属性到我的网络节点上时遇到了麻烦。
下面是我的数据框的一个示例,总共有大约10个列,但在创建网络时我只使用下面显示的5个列。
目前,我只能让我的网络使用边缘属性,如下所示:
g = nx.from_pandas_dataframe(df, 'node_from', 'node_to', edge_attr=['attribute1','attribute2','attribute3'])
该网络将是一个有向网络。下面的数据框中显示的属性是“node_from”节点的属性。“node_to”节点有时会出现作为“node_from”节点。可以在网络中可能显示的所有节点及其各自的属性都显示在df_attributes_only表中。
df_relationship:
node_from: node_to: ........ attribute1: attribute2: attribute3:
jim john ........ tall red fat
...
所有列的值都是单词而不是数字。
我还有另一个数据框,其中包含每个可能的节点及其属性:
df_attributes_only:
id: attribute1: attribute2: attribute3:
jim tall red fat
john small blue fat
...
我需要将上述三个属性分配给它们各自的id,这样每个节点都有它们的3个属性附加在上面。
如果您能帮助我让节点属性与我的网络一起运行,我将不胜感激。