检查列类型
使用 .info() 方法查看 UFO 数据集的各列类型。有两列需要转换:seconds 列应为数值列,但目前被读入为 object;date 列可以转换为 datetime 类型。这样会让后续的特征工程更顺利。
本练习是课程的一部分
Python 中的机器学习预处理
练习说明
- 对
ufo数据集调用.info()方法。 - 将
seconds列的类型转换为float数据类型。 - 将
date列的类型转换为datetime数据类型。 - 再次对
ufo调用.info(),检查更改是否生效。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Print the DataFrame info
print(ufo.____)
# Change the type of seconds to float
ufo["seconds"] = ____
# Change the date column to type datetime
ufo["date"] = ____
# Check the column types
print(ufo.____)