比較 #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:", ____(____) / ____)