Gephi脚本控制台不显示节点

2024-10-03 09:16:46 发布

您现在位置:Python中文网/ 问答频道 /正文

是我遗漏了什么,还是这是Gephi脚本控制台中的一个奇怪的错误?在

控制台显示边,但不显示节点

例如

>>> len(g.edges)
4314
>>> len(g.nodes)
1

>>> g.edges
set([e8926, e8794, e7024 ......])
>>> g.nodes
set([None])

您可以使用datasetPower复制错误网格.gml配备Gephi。 我在来自here for example 的几个数据集上测试了这一点,得到了相同的错误。在

我做错什么了吗?在


Tags: 脚本none网格len节点错误nodesset
3条回答

现在,在最初的问题两年后,这个bug仍然存在,在Gephi的Jython控制台中:

>>> g.nodes
set([None])

但是,我找到了一种解决方法,可以通过脚本控制台直接操作节点,如下所示:

^{pr2}$

通过这样做,我可以像这样操纵节点属性:

>>> node = nodes[0]
>>> attr = node.attributes
>>> value = attr.getValue('attribute_name')
>>> new_value = do_something(value)
>>> attr.setValue('attribute_name', new_value)

下面是我用python编写的一个脚本,用于在完成user1290329在这里所做的操作之后,如果您在恢复边缘位置时遇到困难[https://stackoverflow.com/a/15827459/1645451]

这基本上会将gephi创建的integer Id列映射到edges表。在

    import pandas as pd

    # Once you have re-imported your CSV, and your ID is an Int, 
    # but your edge table is still messed up
    nodes = pd.read_csv('nodes_table.csv')
    edges = pd.read_csv('edges_table.csv')

    # delete any unnecessary cols
    del edges['Label']


    # Create a dictionary with your Node name as the key, 
    # and its Gephi int Id as the value
    # To do this Set index to be col you want the dict keys to be
    # and the dict values will be col you specifiy in the brackets after 'ie ['Id']
    node_dict = nodes.set_index('Label')['Id'].to_dict()

    # Then use the map function, col you are mapping with should have they keys
    # And will fill with value of key when matched
    # In this case we just over-write the Source and Target cols
    edges['Source'] = edges['Source'].map(node_dict)
    edges['Target'] = edges['Target'].map(node_dict)

    edges.to_csv('edges_formatted_for_gephi.csv', index=False)
    edges.head()

现在在gephi数据实验室中,导入电子表格,确保选择了edges选项,然后单击choose the‘edges’formatted_for_盖菲.csv,取消选中createmissing nodes,您的边应该回到gephi图中。:)

有一个名为“数据表”的插件,当你安装它时,你可以看到你的数据集的结构。 我遇到了一个完全一样的问题,我理解了节点id是一个字符串而不是一个数字。如果你想在控制台脚本插件中看到脚本插件executeg.nodes()命令的区别,你可以看到(从“数据表”插件)新创建的节点的id是一个数字而不是字符串。当您在Gephi控制台中执行g.nodes或len(g.nodes)时,您可以看到新创建的节点。 我是这样解决的: 我安装了一个名为“Data Table”的插件,在can“Export Table”中选择它,它告诉你需要导出哪些列,你可以选择任何你想要的,而不是Id,然后选择一个分隔符,按Ok它就会保存它。创建一个新的项目,打开“数据表”插件,然后单击“导入电子表格”,从这里你可以插入一个名为“Id”的新列的数据集,gephi自己把它添加到你的数据集中

相关问题 更多 >