开始使用免费开始使用

设置索引

在本章的最后一步,您将把 stop_datetime 列设置为 DataFrame 的索引。将默认索引替换为 DatetimeIndex 后,按日期和时间分析数据集会更方便,这在课程后续部分会派上用场!

本练习是课程的一部分

使用 pandas 分析警务活动

查看课程

练习说明

  • stop_datetime 设置为 DataFrame 的索引。
  • 检查索引,确认其为 DatetimeIndex
  • 查看 DataFrame 的列,确认 stop_datetime 不再是列之一。

交互式实操练习

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

# Set 'stop_datetime' as the index
ri.____(____, inplace=True)

# Examine the index
print(____)

# Examine the columns
print(____)
编辑并运行代码