資料集介紹

Python 網路分析進階

Eric Ma

Data Carpentry instructor and author of nxviz package

資料集與案例介紹

  • 大學論壇貼文資料集,為期 6 個月
  • 節點分群:學生、論壇
  • 本章活動:
    • 由 pandas DataFrame 建立圖
    • 計算二分圖的單分圖投影
    • 視覺化
    • 時間序列篩選與分析
  • 複習前面用過的函式
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())
[]
Python 網路分析進階

從 DataFrame 建立圖

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

list(G.edges())
[('product1', 'customerC'), ('product1', 'customerA'), 
    ('customerC', 'product2'), ('product2', 'customerB')]
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']
Python 網路分析進階

一起來練習吧!

Python 網路分析進階

Preparing Video For Download...