In [1]:
%config InlineBackend.figure_format ='retina'
%matplotlib inline
import networkx as nx
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Set options
sns.set_style('darkgrid')
pd.set_option("display.max_rows", 10)
def read_excel(filespec):
# read file into pandas DataFrame
answer = pd.read_excel(filespec)
# set column names to lower case for easier typing
answer.columns = [colname.lower() for colname in list(answer.columns.values)]
# return answer
return(answer)
In [24]:
institutions = read_excel("data/HD2016.xlsx")
institutions = institutions.query("cyactive == 1 & iclevel == 1 & ugoffer == 1 & dfrcuscg in [1, 2]")
institutions = institutions[["unitid", "instnm", "city", "stabbr", "longitud", "latitude", "dfrcuscg"]]
institutions
Out[24]:
In [3]:
peer_lists = read_excel("data/CUSTOMCGIDS2016.xlsx")[["unitid", "cgunitid"]]
peer_lists
Out[3]:
In [10]:
peer_lists = pd.merge(peer_lists, institutions, on = "unitid")
In [13]:
peer_graph = nx.from_pandas_edgelist(peer_lists, "unitid", "cgunitid", create_using = nx.DiGraph)
peer_graph.number_of_nodes()
Out[13]:
In [14]:
# nx.draw_networkx(peer_graph)
nx.degree(peer_graph, 181464)
Out[14]:
In [19]:
nx.clustering(peer_graph, 181464)
Out[19]:
In [38]:
nx.shortest_path(peer_graph, 181464, 152080)
Out[38]:
In [39]:
nx.shortest_path_length(peer_graph, 181464, 152080)
Out[39]:
In [53]:
institutions.query("unitid in {}".format(nx.shortest_path(peer_graph, 181464, 152080)))
# unl = nx.bfs_tree(peer_graph, 181464)
# nx.draw_networkx(unl)
Out[53]:
In [63]:
peer_graph[181464]
Out[63]:
In [73]:
nx.draw(nx.subgraph(peer_graph, 181464))
In [43]:
nx.to_pandas_edgelist(peer_graph)
Out[43]:
In [47]:
nx.to_pandas_adjacency(peer_graph)
Out[47]:
In [ ]: