我正在尝试通过这样的csv获取数据来创建分层树:
Node 1 Node 2 Node 3
AL201 AL705 AL500
AL204 AL704 AL500
AL509 AL703 AL500
AL501 AL507 AL500
AL502 AL704 AL500
AL503 AL501 AL500
AL505 AL704 AL500
AL707 AL500 AL500
AL705 AL704 AL500
我已经编写了这段代码,但是我并没有得到我想要的东西,只有一个带有节点的图:
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
data = pd.read_csv(r'C:\Users\flovascio\Documents\Python Scripts\Exercises\Test_Network_2.csv', delimiter = ';')
columns = list(data)
G = nx.DiGraph()
for index, row in data.iterrows():
G.add_edge(row[0], row[1], length=150)
G.add_edge(row[1], row[2], length=150)
nx.draw(G ,edge_color = 'blue' ,width=2, linewidths=1, node_size = 500, with_labels=True)
plt.draw()
plt.show()
有人可以建议我另一种获取层次树的方法吗?
谢谢