-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buque_3_12.py
47 lines (41 loc) · 1.11 KB
/
Buque_3_12.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#%%
import pandas as pd
import numpy as np
import os
import networkx as nx
import pickle
# %%
with open('direct_conections_df.pkl','rb')as file:
data=pickle.load(file)
Conexiones=pd.DataFrame(data)
Conex_1=Conexiones.iloc[0:200,0:6]
# %%
G= nx.from_pandas_edgelist(Conex_1,source='p_cty_code',target='d_cty_code',create_using=nx.DiGraph())
from matplotlib.pyplot import figure
figure(figsize=(12,9))
#nx.draw_shell(G,with_labels=True)
#nx.draw_circular(G)
nx.degree(G)
#si quisieramos crear otro df que muestre los nodos y su numero de conexiones usamos:
conexion= {}
for x in G.nodes:
conexion[x] = len(G[x])
s = pd.Series(conexion, name='Conexiones')
df2 = s.to_frame().sort_values('Conexiones', ascending=False)
#%%
# Density
nx.density(G)
# Clustering
nx.clustering(G)
# Similar al comando anterior
for i in nx.clustering(G).items():
print (i)
# Average clustering
nx.average_clustering(G)
# Diameter
nx.diameter(G)
diameter = nx.diameter(net.to_undirected())
# %%
# %%
# https://www.youtube.com/watch?v=px7ff2_Jeqw
# Rob Chew, Peter Baumgartner | Connected: A Social Network Analysis Tutorial with NetworkX