彙整數值型特徵
當你有許多數值相近、彼此相關的特徵時,計算彙總統計量來建立新特徵會很有幫助。這裡有一個名為 running_times_5k 的 DataFrame,內容是多次跑步成績。請針對資料集中的每個 name,計算其 5 次跑步時間的平均值。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 使用
.loc[]方法選取所有列與相關欄位,對各欄位計算.mean()。 - 列印 DataFrame 的
.head(),查看mean欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Use .loc to create a mean column
running_times_5k["mean"] = ____.loc[____, ____].____(axis=____)
# Take a look at the results
print(____)