解决了将NetworkX代码转换为iGraph代码时发现与from_pandas_adjacency(foo)等效的问题

时间:2019-06-09 12:42:53

标签: networkx igraph adjacency-matrix

我正在尝试将一些NetworkX代码转换为igraph代码,以加快计算速度。

我希望可以将文件中的所有networkx与igraph交换,由于文档的不同,该文件不起作用(事后看来,我应该知道这一点)。我当前遇到的错误是igraph模块中没有from_pandas_adjacency(foo)函数,该函数可以从表示我的邻接矩阵的csv文件中读取。我该如何解决这个问题?

import networkx
import numpy as np
from networkx import algorithms 
from networkx.algorithms import efficiency 
from networkx.algorithms.efficiency import global_efficiency
import pandas


#Generating combos, ignore this
data=pandas.read_csv("ones.csv")
lol1 = data.values.tolist()
data=pandas.read_csv("twos.csv")
lol2 = data.values.tolist()

combo=lol1+lol2
GE_list=[]


#Global efficiency calculations with deletions
for row in combo:
    values = row
    datasafe=pandas.read_csv("b1.csv", index_col=0)
    datasafe.loc[values, :] = 0

    datasafe[values] = 0


    g=networkx.from_pandas_adjacency(datasafe)
    ge=global_efficiency(g)
    GE_list.append(ge)


values = ["s6-8","p9-46v","p47r","p10p","IFSp","IFSa",'IFJp','IFJa','i6-8','a9-46v','a47r','a10p','9p','9a','9-46d','8C','8BL','8AV','8AD','47s','47L','10pp','10d','46','45','44']
datasafe=pandas.read_csv("b1.csv", index_col=0)
datasafe.loc[values, :] = 0

datasafe[values] = 0


g=networkx.from_pandas_adjacency(datasafe)
ge=global_efficiency(g)
GE_list.append(ge)

output=pandas.DataFrame(list(zip(combo, GE_list)))
output.to_csv('delete 1.csv',index=None)

主要错误消息是,igraph模块中没有from_pandas_adjacency(foo)[其中foo是pandas.read_csv(adjacency.csv)输出]函数。如何解决igraph的from_pandas_adjacency等效问题?干杯

0 个答案:

没有答案