開始使用免費開始

比較 #python 與 #rstats

現在我們已經有一個能在多個欄位檢查推文是否包含某個單字的函式,就能把它套用到多個關鍵字並進行比較。讓我們回到資料科學主題標籤的資料集這個例子。我們想比較 #rstats 相對於 #python 出現了多少次。

我們已為你載入資料科學主題標籤資料集 ds_tweets

本練習屬於課程

使用 Python 分析社群媒體資料

檢視課程

練習說明

  • 使用 check_word_in_tweet() 函式,在 ds_tweets 的文字欄位中找出所有 #python 的出現。
  • 針對 #rstats 做相同的事。
  • 列印提到 #python 的推文比例:用 np.sum() 加總 python,再除以 ds_tweets.shape[0]
  • rstats 也做一次。

動手互動練習

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

# Find mentions of #python in all text fields
python = ____(____, ds_tweets)

# Find mentions of #rstats in all text fields
rstats = ____(____, ____)

# Print proportion of tweets mentioning #python
print("Proportion of #python tweets:", ____(____) / ____)

# Print proportion of tweets mentioning #rstats
print("Proportion of #rstats tweets:", ____(____) / ____)
編輯並執行程式碼