我需要将网络节点的程度(以及其他集中度指标)输出到.txt文件中。我可以在以前的 NetworkX / Pandas 版本中做到这一点,但现在出现错误。我正在使用 NetworkX 版本。2.1和Pandas ver。0.23.4:import pandas as pdimport networkx as nxG = nx.Graph()G.add_edges_from([(1,2),(1,3),(2,3),(3,4),(4,5),(4,6)])df = pd.DataFrame(dict( DEGREE = nx.degree(G), DEGREE_CENTRALITY = nx.degree_centrality(G), EIGENVECTOR = nx.eigenvector_centrality(G), KATZ = nx.katz_centrality_numpy(G), CLOSENESS_CENTRALITY = nx.closeness_centrality(G), BETWEENNESS_CENTRALITY = nx.betweenness_centrality(G), CLUSTCOEF = nx.clustering(G),)) #df.index += 1 #df.to_csv('centrality-metrics.csv')错误消息是:Traceback (most recent call last): File "<stdin>", line 8, in <module> File "/home/arthur/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 348, in __init__ mgr = self._init_dict(data, index, columns, dtype=dtype) File "/home/arthur/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 459, in _init_dict return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) File "/home/arthur/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 7356, in _arrays_to_mgr index = extract_index(arrays) File "/home/arthur/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 7405, in extract_index raise ValueError('Mixing dicts with non-Series may lead to 'ValueError: Mixing dicts with non-Series may lead to ambiguous ordering.
添加回答
举报
0/150
提交
取消