開始使用免費開始

轉換欄位型別

如果你查看 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.____)
編輯並執行程式碼