開始使用免費開始

比率

雖然嚴格來說這不一定是網路中的「重要性」指標,但所謂被「ratio'd」是 Twitter 特有的一種網路衡量方式,通常用來判斷一則推文不受歡迎的程度。「The Ratio」指的是用回覆數除以轉推數。就本題而言,只取轉推與回覆網路的入度(in-degree)最符合概念。

已為你載入網路 G_rtG_reply,以及 column_names = ['screen_name', 'degree']

本練習屬於課程

使用 Python 分析社群媒體資料

檢視課程

練習說明

  • 使用圖形方法 .in_degree() 計算轉推網路的入度。
  • 對回覆網路執行相同操作。
  • 使用 .merge() 將兩個 DataFrame 合併。
  • 計算比率。欄位名稱為 degree_replydegree_rt

動手互動練習

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

# Calculate in-degrees and store in DataFrame
degree_rt = pd.DataFrame(list(____.____()), columns = column_names)
degree_reply = pd.DataFrame(list(____.____()), columns = column_names)

# Merge the two DataFrames on screen name
ratio = ____.____(____, on = 'screen_name', suffixes = ('_rt', '_reply'))

# Calculate the ratio
ratio['ratio'] = ____ / ____

# Exclude any tweets with less than 5 retweets
ratio = ratio[ratio['degree_rt'] >= 5]

# Print out first five with highest ratio
print(ratio.sort_values('ratio', ascending = False).head())
編輯並執行程式碼