Question

Am I missing something or is this a strange bug in Gephi scripting console ?

the console shows edges but no nodes

for example

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

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

You can replicate the error using the dataset Power Grid.gml provided with Gephi. I tested this on several datasets from here for example and got the same error.

Am I doing something wrong ?

Was it helpful?

Solution

there is a plugin named "Data Table", when you install it, you can see the structure of your dataset. i had a problem exactly like that, and i understood the node id, is a string not a number. if you want to see the difference in scripting Plugins execute g.nodes() command in Console Scripting Plugin, you can see (from "Data Table" Plugin that) the id of new created node is a number not a string. and when you execute g.nodes or len(g.nodes) in Gephi Console, you can see the new created node. I solve it in this way: i installed a Plugin named "Data Table", in can "Export Table", choose it, it tells you which columns you need to export you choose whatever you want but not the Id, then choose a separator and press Ok it will save it. make a new project, open "Data Table" plugins then click "Import SpreadSheet" from here you can insert your dataset with a new column named "Id" that gephi on its own add it to your DataSet

OTHER TIPS

Now two years after the original question the bug is still there where in the Jython console of Gephi where:

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

However, I found a workaround to directly manipulate the nodes through the scripting console like this:

>>> graph = g.getUnderlyingGraph()
>>> nodes = [node for node in graph.nodes]
>>> nodes
[n0, n1, n2, n3, n4, n5, n6, n7, ...

By doing this I was able to manipulate the node attributes like this:

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

Here is a script I wrote in python for if you are having trouble getting your edges back into place after you have done what user1290329 has done here [https://stackoverflow.com/a/15827459/1645451]

This basically will map your new gephi-created integer Id column to an edges table.

    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()

Now in the gephi data laboratory, import spreadsheet, make sure you choose the edges option, and click choose the 'edges_formatted_for_gephi.csv', uncheck create missing nodes, and your edges should be back in your gephi graph. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top