冉冉说
如果要将文件解释为边缘列表,同时忽略前两个后面的所有值,则以下操作应该有效:columnsimport networkx as nximport csvg = nx.Graph()csvfile = csv.reader(open("test.csv", "r"), delimiter="\t")for line in csvfile: x, y = line[:2] g.add_edge(x, y)print(g.nodes())# ['35467', '17494', '4190', '18822', '37188', '7741', '8561']print(g.edges())# [('35467', '17494'), ('35467', '4190'), ('35467', '18822'), ('37188', '7741'), ('37188', '8561')]