我正在尝试转换Pythonnetworkx
图形到 Gephi 兼容文件。但是,我遇到了一些我不知道如何解决的问题:
问题:
-
我们如何将节点特征向量合并到gexf文件中?我不断收到错误:“TypeError:不允许属性值类型:”。如果我删除下面的节点功能代码,那么它就可以工作,但理想情况下我想包含节点功能。
-
当我将 .gexf 文件加载到 Gephi 中时,由于某种原因没有显示任何内容 - 为什么会发生这种情况?当我删除下面代码的节点功能部分时,我设法获得了一个 gexf 文件。 (应用程序启动,我可以可视化其他测试数据集,但是当我加载下面的文件时,它在右上角显示节点和边计数器,但实际的图形没有显示......我可以吗?需要按其他内容吗?我看了一些 YouTube 教程,图表总是为这些人加载)
我知道有很多帖子,但在浏览了很多帖子并尝试了解决方案之后,我决定发一篇帖子。
示例代码:
我制作了一些模拟代码来展示我正在做的事情:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
%matplotlib inline
# Make the networkx graph
G = nx.Graph()
# Add some cars (just do 4 for now)
G.add_nodes_from([
(1, {'y': 0}),
(2, {'y': 1}),
(3, {'y': 2}),
(4, {'y': 3}),
(5, {'y': 4}),
])
# Add some edges --> A = [(0, 1, 0, 1, 1), (1, 0, 1, 1, 0), (0, 1, 0, 0, 1), (1, 1, 0, 0, 0), (1, 0, 1, 0, 0)]
G.add_edges_from([
(1, 2), (1, 4), (1, 5),
(2, 3), (2, 4),
(3, 2), (3, 5),
(4, 1), (4, 2),
(5, 1), (5, 3)
])
# add the price data to the graph as node features
for node in G.nodes():
G.nodes[node]['x'] = np.random.rand(5) * 5
# This code mounts the google drive
from google.colab import drive
drive.mount('/content/drive')
# convert the graph to Gephi
nx.write_gexf(G, '/content/drive/MyDrive/cars_test.gexf', version="1.2draft")
然后我收到错误:“TypeError:不允许属性值类型:”
任何帮助,将不胜感激。