提取 datetime 组件
在 volunteer 数据集中有多列是 datetime。我们来查看 start_date_date 列,并仅提取月份,用作建模的一个特征。
本练习是课程的一部分
Python 中的机器学习预处理
练习说明
- 将
start_date_date列转换为pandas的 datetime 列,并存入名为start_date_converted的新列中。 - 获取
start_date_converted的月份部分,并存入名为start_date_month的新列中。 - 仅打印
start_date_converted和start_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[[____, ____]].____)