开始使用免费开始使用

提取 datetime 组件

volunteer 数据集中有多列是 datetime。我们来查看 start_date_date 列,并仅提取月份,用作建模的一个特征。

本练习是课程的一部分

Python 中的机器学习预处理

查看课程

练习说明

  • start_date_date 列转换为 pandas 的 datetime 列,并存入名为 start_date_converted 的新列中。
  • 获取 start_date_converted 的月份部分,并存入名为 start_date_month 的新列中。
  • 仅打印 start_date_convertedstart_date_month 两列的 .head()

交互式实操练习

通过完成这段示例代码来试试这个练习。

# First, convert string column to date column
volunteer["start_date_converted"] = pd.____(____)

# Extract just the month from the converted column
volunteer["start_date_month"] = volunteer[____].____

# Take a look at the converted and new month columns
print(volunteer[[____, ____]].____)
编辑并运行代码