转换列的数据类型
查看 volunteer 数据集的类型时,您会发现 hits 列是 object 类型。但如果实际查看该列,会发现它由整数构成。我们把该列转换为 int 类型。
本练习是课程的一部分
Python 中的机器学习预处理
练习说明
- 查看
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.____)