開始使用免費開始

建立回覆網路

回覆網路和轉推網路的結構明顯不同。轉推網路通常代表認同,而回覆則可能代表討論、審議,甚至意見相左。不過網路屬性是一樣的:這是有向網路,來源節點是回覆者,目標節點是被回覆的使用者。

在這個練習中,你將從另一個版本的國情咨文(State of the Union)推文樣本建立回覆網路。這些推文已經載入為 sotu_replies

本練習屬於課程

使用 Python 分析社群媒體資料

檢視課程

練習說明

  • 以 pandas 的邊列表建立回覆網路。
  • 將使用者的螢幕名稱作為 source 參數。
  • 將被回覆者的螢幕名稱作為 target 參數。
  • create_using 參數中指定為有向圖,以確保網路是有向圖。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import networkx
import networkx as nx

# Create reply network from edgelist
G_reply = ____.____(
    sotu_replies,
    ____ = ____,
    ____ = ____,
    ____ = ____)
    
# Print the number of nodes
print('Nodes in reply network:', len(G_reply.nodes()))

# Print the number of edges
print('Edges in reply network:', len(G_reply.edges()))
編輯並執行程式碼