为了账号安全,请及时绑定邮箱和手机立即绑定

NetworkX / Pandas-无法将节点的度数输出到.txt文件中

NetworkX / Pandas-无法将节点的度数输出到.txt文件中

跃然一笑 2021-05-30 10:45:52
我需要将网络节点的程度(以及其他集中度指标)输出到.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.
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 265 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号