Вступ до набору даних

Середній рівень Network Analysis у Python

Eric Ma

Data Carpentry instructor and author of nxviz package

Набір даних і вступ до кейсу

  • Набір даних форуму коледжу, 6 місяців
  • Розбиття вузлів: студенти, форуми
  • Дії в цьому розділі:
    • Побудова графа з pandas DataFrame
    • Обчислення уніпарних проєкцій біпартитного графа
    • Візуалізація
    • Фільтрація та аналіз часових рядів
  • Підсумуємо раніше використані функції
Середній рівень Network Analysis у Python

Графи з DataFrame

df
   customers    products
0  customerA    product1
1  customerB    product2
...
G = nx.Graph()

G.add_nodes_from(df['products'], bipartite='products') G.add_nodes_from(df['customers'], bipartite='customers')
list(G.nodes())
['product1', 'customerC', 'product2', 'customerB', 'customerA']
list(G.edges())
[]
Середній рівень Network Analysis у Python

Графи з DataFrame

G.add_edges_from(zip(df['customers'], df['products']))

list(G.edges())
[('product1', 'customerC'), ('product1', 'customerA'), 
    ('customerC', 'product2'), ('product2', 'customerB')]
Середній рівень Network Analysis у Python

Біпартитні проєкції

cust_nodes = [n for n in G.nodes() if G.nodes[n]
                 ['bipartite'] == 'customers']

prod_nodes = [n for n in G.nodes() if G.nodes[n] ['bipartite'] == 'products']
prodG = nx.bipartite.projected_graph(G, nodes=prod_nodes) custG = nx.bipartite.projected_graph(G, nodes=cust_nodes)
list(prodG.nodes())
['product1', 'product2']
list(custG.nodes())
['customerC', 'customerB', 'customerA']
Середній рівень Network Analysis у Python

Давайте потренуємось!

Середній рівень Network Analysis у Python

Preparing Video For Download...