分開數值與類別欄位
在上一個練習中,你已經探索了資料集的特性,現在可以開始做一些資料前處理。你將從 telco_raw DataFrame 中,依照自訂的類別與數值欄位「唯一值數量」門檻,分開類別與數值變數。pandas 模組已替你載入為 pd。
電信流失的原始資料集 telco_raw 已替你載入為一個 pandas DataFrame。你可以在主控台中先探索它,熟悉資料內容。
本練習屬於課程
Python 的行銷機器學習
練習說明
- 儲存
customerID和Churn的欄位名稱。 - 將唯一值少於 5 的欄位名稱指定給
categorical。 - 從清單中移除
target。 - 將不在
custid、target和categorical中的所有欄位名稱指定給numerical。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Store customerID and Churn column names
custid = ['___']
target = ['___']
# Store categorical column names
categorical = telco_raw.___()[telco_raw.nunique() < ___].keys().tolist()
# Remove target from the list of categorical variables
categorical.remove(___[0])
# Store numerical column names
numerical = [x for x in telco_raw.___ if x not in custid + ___ + categorical]