2013-04-01 25 views
3

我錯過了什麼,或者這是Gephi腳本控制檯中的一個奇怪的錯誤?Gephi腳本控制檯不顯示節點

控制檯顯示的邊緣,但沒有節點

例如

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

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

可以複製使用提供Gephi數據集電源Grid.gml錯誤。 我在here for example的幾個數據集上測試了這個,得到了同樣的錯誤。

我做錯了什麼?

+0

無論發生什麼,它不僅僅是節點:除非我錯過了某些東西,應該有4941個節點和6594個邊緣。 – DSM

回答

3

有一個名爲「數據表」的插件,當您安裝它時,您可以看到數據集的結構。 我有一個問題完全一樣,我明白了節點ID,是一個字符串不是數字。如果您想查看腳本編寫中的差異,請在Console Scripting Plugin中執行g.nodes()命令,您可以看到(從「數據表」插件中)新創建的節點的ID是一個數字而不是字符串。並且在Gephi控制檯中執行g.nodes或len(g.nodes)時,您可以看到新創建的節點。 我這樣解決: 我安裝了一個名爲「數據表」的插件,可以在「導出表」中選擇它,它告訴你需要導出哪些列,選擇你想要的而不是Id,然後選擇一個分隔符,然後按確定它會保存它。創建一個新項目,打開「數據表」插件,然後從這裏單擊「導入SpreadSheet」,您可以將數據集插入一個名爲「Id」的新列,gephi自己將其添加到您的DataSet中

+0

謝謝。我確實安裝了'數據實驗室助手',它確實可以重新設置列(從字符串到整數)。可惜儘管你需要導出並重新導入表格(無法覆蓋Id)。另一個策略 - 我將使用 - 是在python NetworkX中導入圖形並將其保存爲gexf – user1043144

0

這是一個腳本如果你在完成user1290329在這裏完成的工作後遇到了問題,我在python中寫道如下:[https://stackoverflow.com/a/15827459/1645451]

這基本上會將你的新gephi創建的整數Id列映射到邊表。

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_formatted_for_gephi.csv」,取消選中創建缺少的節點,和您的邊緣應重新出現在你gephi圖

現在。 :)

1

現在原題錯誤仍然存​​在,其中在Gephi的Jython的控制檯,兩年後:

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

但是,我發現了一個解決辦法通過腳本控制檯一樣直接操作的節點這樣的:

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

通過這樣做,我能夠操縱節點屬性是這樣的:

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