2023-02-16 16:11:54 +08:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-02-17 23:00:28 +08:00
|
|
|
"execution_count": 1,
|
2023-02-16 16:11:54 +08:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAACyIAAAsQCAYAAABS037aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdebidZWEu7metPe+dZO+MJIQwCciMiKIgoDhrHavVWmvLqcdTT61V69j253Dac1pFW6dWW6sWR9SCKCBQFChzmEkIkDCGzHP2PK7h98faWckmCbAUAeW+rytX1v6G932/bw25rs2zHgrVarUaAAAAAAAAAAAAAIAGFJ/sBQAAAAAAAAAAAAAAv3kEkQEAAAAAAAAAAACAhgkiAwAAAAAAAAAAAAANE0QGAAAAAAAAAAAAABomiAwAAAAAAAAAAAAANEwQGQAAAAAAAAAAAABomCAyAAAAAAAAAAAAANAwQWQAAAAAAAAAAAAAoGGCyAAAAAAAAAAAAABAwwSRAQAAAAAAAAAAAICGCSIDAAAAAAAAAAAAAA0TRAYAAAAAAAAAAAAAGiaIDAAAAAAAAAAAAAA0TBAZAAAAAAAAAAAAAGiYIDIAAAAAAAAAAAAA0DBBZAAAAAAAAAAAAACgYYLIAAAAAAAAAAAAAEDDBJEBAAAAAAAAAAAAgIYJIgMAAAAAAAAAAAAADRNEBgAAAAAAAAAAAAAaJogMAAAAAAAAAAAAADRMEBkAAAAAAAAAAAAAaJggMgAAAAAAAAAAAADQMEFkAAAAAAAAAAAAAKBhgsgAAAAAAAAAAAAAQMMEkQEAAAAAAAAAAACAhgkiAwAAAAAAAAAAAAANa36iJ+zt7c2VV15Z/3nRokVpa2t7opcB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AAAD
|
|
|
|
"text/plain": [
|
|
|
|
"<Figure size 3600x3600 with 1 Axes>"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "display_data"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"import pandas as pd\n",
|
|
|
|
"import networkx as nx\n",
|
|
|
|
"import matplotlib.pyplot as plt\n",
|
|
|
|
"\n",
|
|
|
|
"plt.rcParams['font.sans-serif'] = 'SimHei'\n",
|
|
|
|
"\n",
|
|
|
|
"BomNodes = pd.read_csv('BomNodes.csv', index_col=0)\n",
|
|
|
|
"BomNodes.set_index('Code', inplace=True)\n",
|
|
|
|
"BomCateNet = pd.read_csv('BomCateNet.csv', index_col=0)\n",
|
|
|
|
"BomCateNet.fillna(0, inplace=True)\n",
|
|
|
|
"\n",
|
|
|
|
"G = nx.from_pandas_adjacency(BomCateNet, create_using=nx.MultiDiGraph())\n",
|
|
|
|
"\n",
|
|
|
|
"labels_dict = {}\n",
|
|
|
|
"for code in G.nodes:\n",
|
|
|
|
" labels_dict[code] = BomNodes.loc[code].to_dict()\n",
|
|
|
|
"nx.set_node_attributes(G, labels_dict)\n",
|
|
|
|
"\n",
|
|
|
|
"pos = nx.nx_agraph.graphviz_layout(G, prog=\"twopi\", args=\"\")\n",
|
|
|
|
"temp = {}\n",
|
|
|
|
"for key, value in nx.get_node_attributes(G, 'Name').items():\n",
|
|
|
|
" temp[key] = key + \" \"+ value\n",
|
|
|
|
"node_labels = temp\n",
|
|
|
|
"plt.figure(figsize=(12, 12), dpi=300)\n",
|
|
|
|
"nx.draw_networkx_nodes(G, pos)\n",
|
|
|
|
"nx.draw_networkx_edges(G, pos)\n",
|
|
|
|
"nx.draw_networkx_labels(G, pos, labels = node_labels, font_size=6)\n",
|
|
|
|
"plt.show()\n"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-02-17 23:00:28 +08:00
|
|
|
"execution_count": 2,
|
2023-02-16 16:11:54 +08:00
|
|
|
"metadata": {},
|
2023-02-16 16:58:02 +08:00
|
|
|
"outputs": [],
|
2023-02-16 16:11:54 +08:00
|
|
|
"source": [
|
|
|
|
"dict_nodes = {0: sorted([node for node in G.nodes() if G.out_degree(node)==0])}\n",
|
|
|
|
"level = 1\n",
|
|
|
|
"while True:\n",
|
|
|
|
" nodes = [list(G.predecessors(node)) for node in dict_nodes[level-1]]\n",
|
|
|
|
" nodes = sorted(list(set([i for j in nodes for i in j])))\n",
|
|
|
|
" if nodes:\n",
|
|
|
|
" dict_nodes[level] = nodes\n",
|
|
|
|
" level += 1\n",
|
|
|
|
" else:\n",
|
|
|
|
" break\n",
|
|
|
|
"\n",
|
|
|
|
"Firm = pd.read_csv(\"Firm.csv\")\n",
|
|
|
|
"Firm.fillna(0, inplace=True)\n",
|
|
|
|
"Firm_copy = Firm.copy()\n",
|
|
|
|
"\n",
|
|
|
|
"for tier in list(dict_nodes.keys())[1:]:\n",
|
|
|
|
" for node in dict_nodes[tier]:\n",
|
|
|
|
" list_neighbors = list(G.neighbors(node))\n",
|
|
|
|
" firm_list = Firm_copy.index[(Firm_copy[list_neighbors]==1).all(axis=1)].to_list()\n",
|
|
|
|
" if firm_list:\n",
|
|
|
|
" Firm_copy.loc[firm_list, node] = 1\n",
|
|
|
|
" Firm_copy.loc[firm_list, list_neighbors] = 0\n",
|
|
|
|
"Firm_copy.to_csv('Firm_amended.csv', index=False, encoding='utf-8-sig')"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-02-17 23:00:28 +08:00
|
|
|
"execution_count": 3,
|
2023-02-16 16:11:54 +08:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
2023-02-16 16:58:02 +08:00
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAACyIAAAsQCAYAAABS037aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGli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AAAAAAAAAAAAgIwpIgMAAAAAAAAAAAAAGVNEBgAAAAAAAAAAAAAypogMAAAAAAAAAAAAAGRMERkAAAAAAAAAAAAAyJgiMgAAAAAAAAAAAACQMUVkAAAAAAAAAAAAACBjisgAAAAAAAAAAAAAQMYUkQEAAAAAAAAAAACAjCkiAwAAAAAAAAAAAAAZU0QGAAAAAAAAAAAAADKmiAwAAAAAAAAAAAAAZEwRGQAAAAAAAAAAAADImCIyAAAAAAAAAAAAAJAxRWQAAAAAAAAAAAAAIGOKyAAAAAAAAAAAAABAxhSRAQAAAAAAAAAAAICMKSIDAAAAAAAAAAAAABlTRAYAAAAAAAAAAAAAMqaIDAAAAAAAAAAAAABkTBEZAAAAAAAAAAAAAMiYIjIAAAAAAAAAAAAAkDFFZAAAAAAAAAAAAAAgY4rIAAAAAAAAAAAAAEDGFJEBAAAAAAAAAAAAgIwpIgMAAAAAAAAAAAAAGVNEBgAAAAAAAAAAAAAypogMAAAAAAAAAAAAAGRMERkAAAAAAAAAAAAAyJgiMgAAAAAAAAAAAACQMUVkAAAAAAAAAAAAACBjisgAAAAAAAAAAAAAQMYUkQEAAAAAAAAAAACAjCkiAwAAAAAAAAAAAAAZU0QGAAAAAAAAAAAAADKmiAwAAAAAAAAAAAAAZEwRGQAAAAAAAAAAAADImCIyAAAAAAAAAAAAAJAxRWQAAAAAAAAAAAAAIGOKyAAAAAAAAAAAAABAxhSRAQAAAAAAAAAAAICMKSIDAAAAAAAAAAAAABlTRAYAAAAAAAAAAAAAMqaIDAAAAAA
|
2023-02-16 16:11:54 +08:00
|
|
|
"text/plain": [
|
2023-02-16 16:58:02 +08:00
|
|
|
"<Figure size 3600x3600 with 1 Axes>"
|
2023-02-16 16:11:54 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
"metadata": {},
|
2023-02-16 16:58:02 +08:00
|
|
|
"output_type": "display_data"
|
2023-02-16 16:11:54 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2023-02-16 16:58:02 +08:00
|
|
|
"firm_num_dict = {}\n",
|
|
|
|
"for node in nx.nodes(G):\n",
|
|
|
|
" firm_num_dict[node]= sum(Firm_copy[node]==1)\n",
|
|
|
|
"nx.set_node_attributes(G, firm_num_dict, name=\"Num_Firm\")\n",
|
|
|
|
"\n",
|
|
|
|
"pos = nx.nx_agraph.graphviz_layout(G, prog=\"twopi\", args=\"\")\n",
|
|
|
|
"temp = {}\n",
|
|
|
|
"for key, value in nx.get_node_attributes(G, 'Num_Firm').items():\n",
|
|
|
|
" # temp[key] = key + \" \"+ str(value)\n",
|
|
|
|
" temp[key] = str(value)\n",
|
|
|
|
"node_labels = temp\n",
|
|
|
|
"plt.figure(figsize=(12, 12), dpi=300)\n",
|
|
|
|
"nx.draw_networkx_nodes(G, pos)\n",
|
|
|
|
"nx.draw_networkx_edges(G, pos)\n",
|
|
|
|
"nx.draw_networkx_labels(G, pos, labels = node_labels, font_size=6)\n",
|
|
|
|
"plt.show()"
|
2023-02-16 16:11:54 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2023-02-17 23:00:28 +08:00
|
|
|
"execution_count": 4,
|
2023-02-16 16:11:54 +08:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
|
|
|
"[1, 2, 3, 4, 5]"
|
|
|
|
]
|
|
|
|
},
|
2023-02-17 23:00:28 +08:00
|
|
|
"execution_count": 4,
|
2023-02-16 16:11:54 +08:00
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"list(dict_nodes.keys())[1:]"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "base",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
|
|
|
"version": "3.8.8"
|
|
|
|
},
|
|
|
|
"orig_nbformat": 4,
|
|
|
|
"vscode": {
|
|
|
|
"interpreter": {
|
|
|
|
"hash": "bcdafc093860683ffb58d6956591562b7f8ed5d58147d17d71a5d4d6605a08df"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 2
|
|
|
|
}
|