Do you have a good winter vacation? Our company is really grateful to the mice for taking a rest from 28th to 5th.
However, I think that engineers should train McRefugees to improve their skills at such times.
Today, I will introduce a library called networkx that allows you to draw network diagrams.
--Time required for this work: About 10 minutes --What to prepare
(venv)$pip install networkx
import pandas as pd
df_links = pd.read_csv('https://microlearning.site/pydata/ch8/links.csv')
df_links.head(20)
Make sure a table like the one below is loaded. The related networks are 1.
The drawing of the network diagram is as follows.
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
NUM = len(df_links.index)
for i in range(1,NUM+1):
node_no = df_links.columns[i].strip("Node")#Removed the word "Node"
G.add_node(str(node_no))
for i in range(NUM):
for j in range(NUM):
if df_links.iloc[i][j] == 1:
G.add_edge(str(i),str(j))
nx.draw_networkx(G,nide_color="k",edge_color="k",font_color="w")
plt.show()
Let me give you a rough idea of what you're doing, first add a node A line connects the parts of the table where the nodes are 1 (related parts).
Then, the following network diagram will be displayed (the display will be different each time). The numbers that are closely related to each node come to the center. (4, 5, etc.)
Thank you for your hard work. The shape changes each time you run it. try it.
--2020/1/1 Newly created
Recommended Posts