You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -31,47 +31,53 @@ from mpl_toolkits.basemap import Basemap as Basemap
31
31
For the sake of convenience and scope of this tutorial, the data for trade flows of three product categories - Natural Gas (Hs6: 271111), Coffee (Hs6: 090111) and Diamonds (Hs6: 710210) was extracted to three separate CSV files. These are now imported as pandas dataframe, from where they can be converted to NetworkX Graph objects.
The trade network of each commodity is represented as a directed graph comprising countries (vertices) and trade relationships (edges), with the edges starting from the export countries and pointing to the import countries. Each edge consists of two attributes - value of the trade and the quantity of the traded commodity, that can act as weights for the edges.
@@ -99,7 +105,7 @@ Let us look at the trade network of coffee to understand this further.
latitudes = [lat_long[country][1] for country in lat_long]
143
164
longitudes = [lat_long[country][0] for country in lat_long]
144
165
mx, my = m(longitudes, latitudes)
145
166
pos = {}
146
167
for count, (key, value) in enumerate(postemp.items()):
147
-
if(key in G.nodes):
168
+
ifkey in G.nodes:
148
169
pos[key] = (mx[count], my[count])
149
170
else:
150
-
pos=nx.spring_layout(G, seed=1231)
151
-
nx.draw(G, pos, with_labels=True, node_size=nsize, node_color=[mapper.to_rgba(i) for i in indeg_dict.values()])
171
+
pos = nx.spring_layout(G, seed=1231)
172
+
nx.draw(
173
+
G,
174
+
pos,
175
+
with_labels=True,
176
+
node_size=nsize,
177
+
node_color=[mapper.to_rgba(i) for i in indeg_dict.values()],
178
+
)
152
179
plt.show()
153
180
```
154
181
@@ -197,7 +224,7 @@ Now, when we remove the trade link between Russia and Japan, we can observe chan
197
224
198
225
```{code-cell} ipython3
199
226
# removing trade link between Russia and Japan
200
-
G_natural_gas.remove_edge('RUS', 'JPN')
227
+
G_natural_gas.remove_edge("RUS", "JPN")
201
228
draw_pretty(G_natural_gas, geo=False)
202
229
```
203
230
@@ -214,7 +241,12 @@ Closeness centrality is an indicator of the distance of a node from other nodes
214
241
In betweenness centrality, the location of the node in the network is more essential than the number of nodes linked. It indicates how important a country is in terms of connecting other countries. Countries having a high betweenness centrality operate as a commercial bridge with other countries in the trade network. Betweenness centrality therefore quantifies the extent to which a certain node operates as an intermediate or gatekeeper in the network.
215
242
216
243
```{code-cell} ipython3
217
-
total_outgoing_weight = {node: sum(data['value']/1000000 for _, _, data in G_coffee.out_edges(node, data=True)) for node in G_coffee}
244
+
total_outgoing_weight = {
245
+
node: sum(
246
+
data["value"] / 1000000 for _, _, data in G_coffee.out_edges(node, data=True)
0 commit comments