回答編集履歴
2
コード修正
test
CHANGED
@@ -1,3 +1,195 @@
|
|
1
|
-
out_degreeは**ノードから出ていくエッジ**の数ということなので、無向グラフだからその属性が無いのではないでしょうか。
|
1
|
+
out_degreeは**ノードから出ていくエッジ**の数ということなので、無向グラフだからその属性が無いのではないでしょうか。in_degreeも同様ですね。
|
2
2
|
|
3
3
|
[networkx.DiGraph.out_degree](https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.DiGraph.out_degree.html)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
あと、G.get_edge_dataが大文字になっていました。
|
8
|
+
|
9
|
+
以上を修正したのが下記です。
|
10
|
+
|
11
|
+
```python3
|
12
|
+
|
13
|
+
import networkx as nx
|
14
|
+
|
15
|
+
import csv
|
16
|
+
|
17
|
+
import pandas as pd
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
# csvファイルの読み込み
|
22
|
+
|
23
|
+
Data = open('test.csv', "r")
|
24
|
+
|
25
|
+
next(Data, None) # CSVデータの最初の行をスキップ
|
26
|
+
|
27
|
+
Graphtype = nx.Graph() # 無向グラフを定義
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
G = nx.parse_edgelist(Data, delimiter=',', create_using=Graphtype,
|
32
|
+
|
33
|
+
nodetype=int, data=(('weight', float),))
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
for x in G.nodes():
|
38
|
+
|
39
|
+
print ("Node:", x, "has total #degree:",G.degree(x))
|
40
|
+
|
41
|
+
for u,v in G.edges():
|
42
|
+
|
43
|
+
print ("Weight of Edge ("+str(u)+","+str(v)+")", G.get_edge_data(u,v))
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
nx.draw(G)
|
48
|
+
|
49
|
+
plt.show()
|
50
|
+
|
51
|
+
"""
|
52
|
+
|
53
|
+
Node: 202 has total #degree: 1
|
54
|
+
|
55
|
+
Node: 237 has total #degree: 1
|
56
|
+
|
57
|
+
Node: 280 has total #degree: 1
|
58
|
+
|
59
|
+
Node: 281 has total #degree: 1
|
60
|
+
|
61
|
+
Node: 118 has total #degree: 2
|
62
|
+
|
63
|
+
Node: 38 has total #degree: 9
|
64
|
+
|
65
|
+
Node: 139 has total #degree: 9
|
66
|
+
|
67
|
+
Node: 158 has total #degree: 9
|
68
|
+
|
69
|
+
Node: 160 has total #degree: 11
|
70
|
+
|
71
|
+
Node: 236 has total #degree: 9
|
72
|
+
|
73
|
+
Node: 282 has total #degree: 11
|
74
|
+
|
75
|
+
Node: 283 has total #degree: 9
|
76
|
+
|
77
|
+
Node: 284 has total #degree: 9
|
78
|
+
|
79
|
+
Node: 285 has total #degree: 9
|
80
|
+
|
81
|
+
Node: 286 has total #degree: 9
|
82
|
+
|
83
|
+
Node: 6 has total #degree: 3
|
84
|
+
|
85
|
+
Node: 240 has total #degree: 3
|
86
|
+
|
87
|
+
Weight of Edge (202,237) {'weight': 1.0}
|
88
|
+
|
89
|
+
Weight of Edge (280,281) {'weight': 1.0}
|
90
|
+
|
91
|
+
Weight of Edge (118,118) {'weight': 1.0}
|
92
|
+
|
93
|
+
Weight of Edge (38,139) {'weight': 1.0}
|
94
|
+
|
95
|
+
Weight of Edge (38,158) {'weight': 1.0}
|
96
|
+
|
97
|
+
Weight of Edge (38,160) {'weight': 1.0}
|
98
|
+
|
99
|
+
Weight of Edge (38,236) {'weight': 2.0}
|
100
|
+
|
101
|
+
Weight of Edge (38,282) {'weight': 1.0}
|
102
|
+
|
103
|
+
Weight of Edge (38,283) {'weight': 1.0}
|
104
|
+
|
105
|
+
Weight of Edge (38,284) {'weight': 1.0}
|
106
|
+
|
107
|
+
Weight of Edge (38,285) {'weight': 1.0}
|
108
|
+
|
109
|
+
Weight of Edge (38,286) {'weight': 1.0}
|
110
|
+
|
111
|
+
Weight of Edge (139,158) {'weight': 1.0}
|
112
|
+
|
113
|
+
Weight of Edge (139,160) {'weight': 1.0}
|
114
|
+
|
115
|
+
Weight of Edge (139,236) {'weight': 1.0}
|
116
|
+
|
117
|
+
Weight of Edge (139,282) {'weight': 1.0}
|
118
|
+
|
119
|
+
Weight of Edge (139,283) {'weight': 1.0}
|
120
|
+
|
121
|
+
Weight of Edge (139,284) {'weight': 1.0}
|
122
|
+
|
123
|
+
Weight of Edge (139,285) {'weight': 1.0}
|
124
|
+
|
125
|
+
Weight of Edge (139,286) {'weight': 1.0}
|
126
|
+
|
127
|
+
Weight of Edge (158,160) {'weight': 1.0}
|
128
|
+
|
129
|
+
Weight of Edge (158,236) {'weight': 1.0}
|
130
|
+
|
131
|
+
Weight of Edge (158,282) {'weight': 1.0}
|
132
|
+
|
133
|
+
Weight of Edge (158,283) {'weight': 1.0}
|
134
|
+
|
135
|
+
Weight of Edge (158,284) {'weight': 1.0}
|
136
|
+
|
137
|
+
Weight of Edge (158,285) {'weight': 1.0}
|
138
|
+
|
139
|
+
Weight of Edge (158,286) {'weight': 1.0}
|
140
|
+
|
141
|
+
Weight of Edge (160,236) {'weight': 1.0}
|
142
|
+
|
143
|
+
Weight of Edge (160,282) {'weight': 2.0}
|
144
|
+
|
145
|
+
Weight of Edge (160,283) {'weight': 1.0}
|
146
|
+
|
147
|
+
Weight of Edge (160,284) {'weight': 1.0}
|
148
|
+
|
149
|
+
Weight of Edge (160,285) {'weight': 1.0}
|
150
|
+
|
151
|
+
Weight of Edge (160,286) {'weight': 1.0}
|
152
|
+
|
153
|
+
Weight of Edge (160,240) {'weight': 1.0}
|
154
|
+
|
155
|
+
Weight of Edge (160,6) {'weight': 1.0}
|
156
|
+
|
157
|
+
Weight of Edge (236,282) {'weight': 1.0}
|
158
|
+
|
159
|
+
Weight of Edge (236,283) {'weight': 1.0}
|
160
|
+
|
161
|
+
Weight of Edge (236,284) {'weight': 1.0}
|
162
|
+
|
163
|
+
Weight of Edge (236,285) {'weight': 1.0}
|
164
|
+
|
165
|
+
Weight of Edge (236,286) {'weight': 1.0}
|
166
|
+
|
167
|
+
Weight of Edge (282,283) {'weight': 1.0}
|
168
|
+
|
169
|
+
Weight of Edge (282,284) {'weight': 1.0}
|
170
|
+
|
171
|
+
Weight of Edge (282,285) {'weight': 1.0}
|
172
|
+
|
173
|
+
Weight of Edge (282,286) {'weight': 1.0}
|
174
|
+
|
175
|
+
Weight of Edge (282,6) {'weight': 1.0}
|
176
|
+
|
177
|
+
Weight of Edge (282,240) {'weight': 1.0}
|
178
|
+
|
179
|
+
Weight of Edge (283,284) {'weight': 1.0}
|
180
|
+
|
181
|
+
Weight of Edge (283,285) {'weight': 1.0}
|
182
|
+
|
183
|
+
Weight of Edge (283,286) {'weight': 1.0}
|
184
|
+
|
185
|
+
Weight of Edge (284,285) {'weight': 1.0}
|
186
|
+
|
187
|
+
Weight of Edge (284,286) {'weight': 1.0}
|
188
|
+
|
189
|
+
Weight of Edge (285,286) {'weight': 1.0}
|
190
|
+
|
191
|
+
Weight of Edge (6,240) {'weight': 2.0}
|
192
|
+
|
193
|
+
"""
|
194
|
+
|
195
|
+
```
|
1
修正
test
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
out_degreeはノードから出ていくエッジの数ということなので、無向グラフ
|
1
|
+
out_degreeは**ノードから出ていくエッジ**の数ということなので、無向グラフだからその属性が無いのではないでしょうか。
|
2
2
|
|
3
3
|
[networkx.DiGraph.out_degree](https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.DiGraph.out_degree.html)
|