開始使用免費開始

尋找關鍵字

計算已知關鍵字,是你在分析 Twitter 資料集中的文字資料時最先會用到的方法之一。在這個資料集中,你要在一批與 data science 相關的推文裡,計算特定主題標籤出現的次數。為此,你會使用 pandas Series 物件的字串方法來完成。

pandasnumpy 分別已匯入為 pdnp。功能更完整的 flatten_tweetsdata_science_json 也已為你載入。

本練習屬於課程

使用 Python 分析社群媒體資料

檢視課程

練習說明

  • 使用 flatten_tweets() 攤平推文並存成 flat_tweets
  • 使用 pandas 的 DataFrame 建構子將推文轉為 DataFrame。
  • 'text' 欄位中尋找 #python 的出現,忽略大小寫。
  • 列印提到 #python 的推文比例:用 np.sum()python 加總,並除以推文總數。

動手互動練習

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

# Flatten the tweets and store them
____ = ____(____)

# Convert to DataFrame
ds_tweets = ____.____(____)

# Find mentions of #python in 'text'
python = ____[____].____.____(____, ____)

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