轉換欄位型別
如果你查看 volunteer 資料集的型別,會發現 hits 欄位是 object。但實際檢視該欄位時,內容其實是整數。把這個欄位轉換成 int 型別吧。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 先查看
hits欄位的.head()。 - 將
hits欄位轉換為int型別。 - 再次查看資料集的
.dtypes,留意該欄位的型別已經改變。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the head of the hits column
print(volunteer["hits"].____)
# Convert the hits column to type int
volunteer["hits"] = ____
# Look at the dtypes of the dataset
print(volunteer.____)